Registry / web-framework / django-deprecate-fields

django-deprecate-fields

JSON →
library0.2.3pypypi✓ verified 24d ago

This package allows deprecating Django model fields and enables their removal in a backwards-compatible manner. It's particularly useful for maintaining migration consistency during rolling deployments where multiple application versions might run in parallel. The current version is 0.2.3, and releases are driven by changes merged to the main branch.

pip install django-deprecate-fields
INSTALL
IMPORT
SIG · DJANGO-DEPRECATE-F
D
django-deprecate-fields
web-frameworkpythonv0.2.3
Install
3.5s avg
Import
259ms
Disk
66MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.270s · 66.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.5s · import 0.248s · 67MB
66MB installed
● package 66MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

deprecate_field
from django_deprecate_fields import deprecate_field

To deprecate a model field, import `deprecate_field` and wrap the existing field definition with it. After this, run `makemigrations`. The package automatically handles making the field nullable. The `return_instead` argument can be used to specify a value or callable to return when the deprecated field is accessed.

from django.db import models from django_deprecate_fields import deprecate_field class MyModel(models.Model): # Original field old_field = models.CharField(max_length=255) # To deprecate old_field, wrap it with deprecate_field # Run './manage.py makemigrations' after this change. deprecated_field = deprecate_field(models.CharField(max_length=255, null=True, blank=True), return_instead='default_value_or_none') # After deprecation and deployment, old_field can be safely removed. # deprecated_field = models.CharField(max_length=255) # This is how it would look after the first step # Then, after successful deployment, it can be entirely removed and a new migration created.
Debug
Known issues
gotchaWhen a field is deprecated, it automatically becomes nullable. You must generate a new migration (`python manage.py makemigrations`) to apply this change to your database schema.
fix
Run `python manage.py makemigrations` after wrapping a field with `deprecate_field`, and then apply the migration.
affects: All
gotchaBy default, accessing a deprecated field will log an `ERROR` message. To make it raise an exception (e.g., in development or CI environments) set `DEPRECATED_FIELD_STRICT = True` in your Django settings.
fix
Add `DEPRECATED_FIELD_STRICT = True` to your Django `settings.py` file to convert access warnings into exceptions.
affects: All
breakingThe complete removal of a field should be a two-step deployment process, especially in a rolling deploy scenario. First, mark the field as deprecated and deploy. Second, once the deprecated version is stable, remove the field definition entirely from the model and deploy again with a new migration.
fix
Follow the two-step removal process: 1. Deprecate field, `makemigrations`, deploy. 2. Remove field from model, `makemigrations`, deploy.
affects: All
gotchaIf you use custom Django migration commands (e.g., `pgmakemigrations`), the `deprecate_field` wrapper might not return the actual field during these commands. You must specify these commands in your settings using `DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND` to ensure correct behavior.
fix
Add `DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND = {"your_custom_command"}` to your Django `settings.py`.
affects: All
Errors
Common errors & fixes
Noisy errors on startup
This issue, noted on the project's GitHub, indicates unexpected warnings or errors appearing when a Django application starts up, potentially related to how `deprecate_field` interacts with the application loading process outside of migration commands.
fix
While the exact fix depends on the underlying cause of the 'noisy errors,' users should check the `django-deprecate-fields` GitHub issues for specific resolutions or workarounds. It may involve adjusting Django settings or ensuring correct application of `deprecate_field`.
OperationalError: no such column: myapp_mymodel.old_field
This error typically occurs during a rolling deployment when an old version of the application attempts to access a database column that has already been removed by a migration applied by a newer version of the application. The `django-deprecate-fields` library is designed to prevent this by enabling a phased removal of fields.
fix
To resolve this safely, use `django-deprecate-fields` in a two-phase deployment: first, wrap the field definition in `deprecate_field()` and deploy, allowing all running instances to use the deprecated (but still existing) column. After ensuring all old code references are gone and a new migration makes the column nullable, then in a subsequent deployment, remove the field entirely from the model and apply a migration to drop the column from the database.
django.db.utils.IntegrityError: NOT NULL constraint failed: myapp_mymodel.new_field
This error occurs when an application attempts to insert or update a record without providing a value for a new non-nullable field, after a migration has added that field to the database. This is especially problematic in rolling deployments where older code might not be aware of the new field.
fix
When adding a new non-nullable field, ensure a two-phase deployment. Initially, add the field as nullable (or with a default) and deploy. Once all application instances are running the code aware of the new field, then update the field to be non-nullable (if desired) in a subsequent deployment. While `django-deprecate-fields` is primarily for *removing* fields, its principles of phased deployment apply to safely adding non-nullable fields as well.
Upgrade
Version history
0.2.3latest on PyPI · released Jan 20, 2026
Audit
Dependencies
DjangorequiredCore dependency for Django model fields and migrations.
Agent activity
9 hits · last 30 days
node
8
Resources
django-deprecate-fields — pip install django-deprecate-fields · libregistry