This package allows deprecating model fields and allows removing them in a backwards compatible manner.
Maintained. Last release 10 months ago, commits in 2 of the last 26 weeks. Weaker on commit activity and release cadence.
pip install django-deprecate-fieldsDjango - Deprecate Field
Installation
pip install django-deprecate-fields
Usage
Assume the simple following model:
from django.db import models
class MyModel(models.Model):
field1 = models.CharField()
field2 = models.CharField()
In order to remove field1, it should first be marked as deprecated:
from django.db import models
from django_deprecate_fields import deprecate_field
class MyModel(models.Model):
field1 = deprecate_field(models.CharField())
field2 = models.CharField()
Secondly, makemigrations should be called, which will change the field to be nullable. Any lingering references to it
in your code will return None (or optionally any value or callable passed to deprecate_field as the
return_instead argument)
Lastly, after the changes above have been deployed, field1 can then safely be removed in the model (plus another
makemigrations run)
Custom django commands
If you need the actual field to be returned when a django command other
than makemigrations, migrate or showmigrations is run, you can specify the
DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND parameter in the settings.
For instance if you generate migrations with pgmakemigrations instead of makemigrations,
you can add this to your settings:
DEPRECATE_FIELD_CUSTOM_MIGRATION_COMMAND = {"pgmakemigrations"}