Django Add Default Value for PostgreSQL
Django Migration Operation that can be used to transfer a field's default value to the database scheme.
Based on django-add-default-value by 3YOURMIND. This variant drops support for other databases, specifically the Azure ODBC driver which does not support current versions of Django.
Dependencies
- Python 3.6, 3.7, or 3.8
- Django 2.2 or 3.0
Installation
pip install django-add-default-value-postgresql
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 an autogenerated Migration that adds a new field:
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.
Testing
You can test against multiple versions of Django using tox. To test across Python versions, use pyenv to run tox under each version.
License
django-add-default-value-postgresql is released under the Apache 2.0 License, based on django-add-default-value by 3YOURMIND which is also released under the Apache 2.0 License.
Changes from original source
- removed MySQL-related code
- removed MSSQL-related code
- added allow_migrate_model check on database_forwards and database_backwards
- added support for Python 3.7 and 3.8, dropped support for <3.6
- added support for Django 2.2 and 3.0, dropped support for <2.2
Metadata
Release files for django-add-default-value-postgresql 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-add-default-value-postgresql-1.0.0.tar.gz | 4.7 kB | Without provenance | Details for django-add-default-value-postgresql-1.0.0.tar.gz |
Release files / django-add-default-value-postgresql-1.0.0.tar.gz
| Download URL | django-add-default-value-postgresql-1.0.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07643c56cf795f6cd6dab31f3d974e65ccbe07817f8dbd3af8b9ae746c619c1a
|
|
BLAKE2b-256 checksum How to use checksums |
adfbbe436540ac4229bbda00ba8ec6d48684363190789dc2cd03a518ca779c47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
|
Security for django-add-default-value-postgresql 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.