Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

This django Migration Operation can be used to transfer a fields default value to the database scheme.

Project description

Django Add Default Value

Django Migration Operation that can be used to transfer a field's default value to the database scheme.

PyPi License Contributing 3yourminD-Careers Stars

Supported Databases

  • MySQL (or compatible)
  • PostgreSQL
  • MSSQL (currently not tested)
  • CockroachDB


pip install django-add-default-value

You can then use AddDefaultValue in your migration file to transfer the default values to your database. Afterwards, it's just the usual ./ migrate.


Add this manually to a autogenerated Migration, that adds a new field::



Given the following migration::

operations = [
        field=models.CharField(default='my_default', max_length=255),

Modify the migration to add a default value::

+from django_add_default_value import AddDefaultValue
 operations = [
         field=models.CharField(default='my_default', max_length=255),
+    AddDefaultValue(
+        model_name='my_model',
+        name='my_field',
+        value='my_default'
+    )

If you check python sqlmigrate [app name] [migration], you will see that the default value now gets set.


First of all, thank you very much for contributing to this project. Please base your work on the master branch and target master in your pull request.

To succesfully use the dbshell management command (very useful for debugging), the client binaries for the respective database engines are needed.

Then install pipenv. Edit the Pipfile to select your Django version and the accompanying MS-SQL driver. Make sure you don't commit this change in any pull request - we always set it to the oldest supported version.

Once you've updated the Pipfile, run pipenv install --python 3 --dev. You should now have a working development environment as a virtualenv. To access it, run pipenv shell or prefix commands with pipenv run. For more information see the pipenv documentation.


Copy the relevant sample settings file in test_project to the file without .sample in it. Adjust the values to match your environment (or match your environment to the values).

You should now be able to run the tests using tox. Select your environment when needed, using the -e command line flag. See Tox's excellent documentation.


django-add-default-value is released under the Apache 2.0 License.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-add-default-value, version 0.9.0
Filename, size File type Python version Upload date Hashes
Filename, size django_add_default_value-0.9.0-py3-none-any.whl (10.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-add-default-value-0.9.0.tar.gz (7.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page