{"id":3458,"library":"django-deprecate-fields","title":"Django Deprecate Fields","description":"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.","status":"active","version":"0.2.3","language":"en","source_language":"en","source_url":"https://github.com/3YOURMIND/django-deprecate-fields","tags":["django","models","fields","deprecation","migrations","deployment","backward-compatibility"],"install":[{"cmd":"pip install django-deprecate-fields","lang":"bash","label":"Pip"}],"dependencies":[{"reason":"Core dependency for Django model fields and migrations.","package":"Django","optional":false}],"imports":[{"symbol":"deprecate_field","correct":"from django_deprecate_fields import deprecate_field"}],"quickstart":{"code":"from django.db import models\nfrom django_deprecate_fields import deprecate_field\n\nclass MyModel(models.Model):\n    # Original field\n    old_field = models.CharField(max_length=255)\n\n    # To deprecate old_field, wrap it with deprecate_field\n    # Run './manage.py makemigrations' after this change.\n    deprecated_field = deprecate_field(models.CharField(max_length=255, null=True, blank=True), return_instead='default_value_or_none')\n    # After deprecation and deployment, old_field can be safely removed.\n    # deprecated_field = models.CharField(max_length=255) # This is how it would look after the first step\n    # Then, after successful deployment, it can be entirely removed and a new migration created.","lang":"python","description":"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."},"warnings":[{"fix":"Run `python manage.py makemigrations` after wrapping a field with `deprecate_field`, and then apply the migration.","message":"When 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Add `DEPRECATED_FIELD_STRICT = True` to your Django `settings.py` file to convert access warnings into exceptions.","message":"By 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Follow the two-step removal process: 1. Deprecate field, `makemigrations`, deploy. 2. Remove field from model, `makemigrations`, deploy.","message":"The 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.","severity":"breaking","affected_versions":"All"},{"fix":"Add `DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND = {\"your_custom_command\"}` to your Django `settings.py`.","message":"If 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.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}