{"id":19057182,"url":"https://github.com/3yourmind/django-add-default-value","last_synced_at":"2025-04-12T22:35:40.053Z","repository":{"id":37514024,"uuid":"117538065","full_name":"3YOURMIND/django-add-default-value","owner":"3YOURMIND","description":"This django Migration Operation can be used to transfer a Fields default value to the database scheme.","archived":false,"fork":false,"pushed_at":"2024-03-20T15:30:26.000Z","size":90,"stargazers_count":137,"open_issues_count":8,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-04T01:39:35.854Z","etag":null,"topics":["database","django","mysql","postgresql","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/3YOURMIND.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-15T11:41:13.000Z","updated_at":"2025-03-11T17:08:02.000Z","dependencies_parsed_at":"2024-06-18T18:29:32.661Z","dependency_job_id":null,"html_url":"https://github.com/3YOURMIND/django-add-default-value","commit_stats":{"total_commits":73,"total_committers":14,"mean_commits":5.214285714285714,"dds":0.6575342465753424,"last_synced_commit":"c7f5f5869ae6ecf93760f061ff38c00bab820b2d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3YOURMIND%2Fdjango-add-default-value","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3YOURMIND%2Fdjango-add-default-value/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3YOURMIND%2Fdjango-add-default-value/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3YOURMIND%2Fdjango-add-default-value/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3YOURMIND","download_url":"https://codeload.github.com/3YOURMIND/django-add-default-value/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248642501,"owners_count":21138351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","django","mysql","postgresql","python"],"created_at":"2024-11-08T23:53:43.484Z","updated_at":"2025-04-12T22:35:40.031Z","avatar_url":"https://github.com/3YOURMIND.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Django Add Default Value\n========================\n\nDjango Migration Operation that can be used to transfer a field's default value\nto the database scheme.\n\n[![PyPi](https://img.shields.io/pypi/v/django-add-default-value.svg?branch=master)](https://pypi.python.org/pypi/django-add-default-value/)\n[![License](https://img.shields.io/github/license/3yourmind/django-add-default-value.svg)](./LICENSE)\n[![Contributing](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/django-add-default-value/pulls)\n[![3yourminD-Careers](https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg)](https://www.3yourmind.com/career)\n[![Stars](https://img.shields.io/github/stars/3YOURMIND/django-add-default-value.svg?style=social\u0026label=Stars)](https://github.com/3YOURMIND/django-add-default-value/stargazers)\n\n\nSupported Databases\n------------\n\n* MySQL (or compatible)\n* PostgreSQL\n* MSSQL (currently not tested)\n* CockroachDB\n\nInstallation\n------------\n`pip install django-add-default-value`\n\nYou can then use ``AddDefaultValue`` in your migration file to transfer the default\nvalues to your database. Afterwards, it's just the usual ``./manage.py migrate``.\n\nUsage\n-----\n\nAdd this manually to a autogenerated Migration, that adds a new field\n\n```python\nAddDefaultValue(\n    model_name='my_model',\n    name='my_field',\n    value='my_default'\n)\n```\n\n### Example\n\nGiven the following migration:\n\n**BEFORE**\n\n```python\nfrom django.db import migrations, models\n\n\nclass Migration(migrations.Migration):\n    dependencies = [\n        ...\n    ]\n\n    operations = [\n         migrations.AddField(\n             field=models.CharField(default='my_default', max_length=255),\n             model_name='my_model',\n             name='my_field',\n         ),\n     ]\n```\n\nModify the migration to add a default value:\n\n**AFTER**\n\n```python\nfrom django.db import migrations, models\n\nfrom django_add_default_value import AddDefaultValue\n\n\nclass Migration(migrations.Migration):\n    dependencies = [\n        ...\n    ]\n\n    operations = [\n         migrations.AddField(\n             field=models.CharField(default='my_default', max_length=255),\n             model_name='my_model',\n             name='my_field',\n         ),\n         AddDefaultValue(\n             model_name='my_model',\n             name='my_field',\n             value='my_default'\n         )\n     ]\n```\n\nIf you check ``python manage.py sqlmigrate [app name] [migration]``,\nyou will see that the default value now gets set.\n\nContributing\n------------\n\nFirst of all, thank you very much for contributing to this project. Please base\nyour work on the ``master`` branch and target ``master`` in your pull request.\n\nTo succesfully use the `dbshell` management command (very useful for debugging),\nthe client binaries for the respective database engines are needed.\n\nThen install [pipenv](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv).\nEdit the `Pipfile` to select your Django version and the accompanying MS-SQL\ndriver. Make sure you don't commit this change in any pull request - we always\nset it to the oldest supported version.\n\nOnce you've updated the Pipfile, run `pipenv install --python 3 --dev`. You\nshould now have a working development environment as a virtualenv. To access it,\nrun `pipenv shell` or prefix commands with `pipenv run`. For more information\nsee the [pipenv documentation](https://pipenv.readthedocs.io/en/latest/basics/).\n\n### Testing\nCopy the relevant sample settings file in `test_project` to the file without\n `.sample` in it. Adjust the values to match your environment (or match your\nenvironment to the values).\n\nYou should now be able to run the tests using `tox`. Select your environment\nwhen needed, using the `-e` command line flag. See\n[Tox's excellent documentation](https://tox.readthedocs.io/en/latest/).\n\n\nLicense\n-------\n\n``django-add-default-value`` is released under the Apache 2.0 License.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3yourmind%2Fdjango-add-default-value","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3yourmind%2Fdjango-add-default-value","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3yourmind%2Fdjango-add-default-value/lists"}