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://pypi.python.org/pypi/django-add-default-value/) [![](https://img.shields.io/github/license/3yourmind/django-add-default-value.svg)](./LICENSE) [![](https://img.shields.io/badge/PR-welcome-green.svg)](https://github.com/3YOURMIND/django-add-default-value/pulls) [![](https://img.shields.io/badge/3YOURMIND-Hiring-brightgreen.svg)](https://www.3yourmind.com/career) [![](https://img.shields.io/github/stars/3YOURMIND/django-add-default-value.svg?style=social&label=Stars)](https://github.com/3YOURMIND/django-add-default-value/stargazers)

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.7.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

django_add_default_value-0.0.7-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-add-default-value-0.0.7.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for django-add-default-value-0.0.7.tar.gz
Algorithm Hash digest
SHA256 59ec4a85d51fce0e0990ac5ef140b39206ad7b6e35717345685c829d0062360a
MD5 866375ca053c21c4956d9f35ce576ad2
BLAKE2b-256 ce5c8da0802dd81d4a100a4114d38ff2b8829db12c794038c5b5a969d35d6b43

See more details on using hashes here.

File details

Details for the file django_add_default_value-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: django_add_default_value-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for django_add_default_value-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6eec65872371b20eb227dfeeea1b3cec9a5552fc851ec9962684e0c2a2b25c11
MD5 1f86ef7b30b8421d310e3a6c930bc5ab
BLAKE2b-256 5045680f491fc730d4fc5a0b798da46965f365c7060f655983a095b64d461c0b

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