Skip to main content

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

Project description

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

https://img.shields.io/pypi/v/django-add-default-value.svg?branch=master https://img.shields.io/github/license/3yourmind/django-add-default-value.svg https://img.shields.io/badge/PR-welcome-green.svg https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg https://img.shields.io/github/stars/3YOURMIND/django-add-default-value.svg?style=social&label=Stars

Dependencies

  • MySQL (or compatible)

  • PostgreSQL

Installation

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 ./manage.py migrate.

Usage

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

AddDefaultValue(
    model_name='my_model',
    name='my_field',
    value='my_default'
)

Example

Given the following migration:

operations = [
    migrations.AddField(
        field=models.CharField(default='my_default', max_length=255),
        model_name='my_model',
        name='my_field',
    ),
]

Modify the migration to add a default value:

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

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

Contributing

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.

License

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.

Source Distribution

django-add-default-value-0.0.3.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-add-default-value-0.0.3.tar.gz.

File metadata

File hashes

Hashes for django-add-default-value-0.0.3.tar.gz
Algorithm Hash digest
SHA256 b1c1968557a6eb24a186ed6859fd869e1b1be7226f146ad9b9e999c05aa64948
MD5 7cd410fb41dc5e4908fab2704255ba9b
BLAKE2b-256 c19f1f2988ef034ab47e9bf5af792abd7209eb53bfae7b3340281d9ae9804046

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page