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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file django_add_default_value-0.0.8-py3-none-any.whl
.
File metadata
- Download URL: django_add_default_value-0.0.8-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/38.6.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 293648bedb6a5614e701c746326539306dd48e0ac90ff0993f936abbcf18d189 |
|
MD5 | 8721c4623d1bdba6ae34e1787d9c1fde |
|
BLAKE2b-256 | 1c2e7cbf78c6dab9623744f8f16a4a0b0a4e48c4edf573b25c3c836747c0ff30 |