Help to remove a django model fields without downtime.
Use @deprecated_fields(fieldnames=[]) to generate logs when one of the fieldnames is used:
@deprecated_fields(["is_active"])
class ModelWithDeprecatedField(models.Model):
name = models.CharField(max_length=64)
is_active = models.BooleanField()Use @removed_field(fieldnames=[]) to raise error when one of the fieldnames is used:
@removed_fields(["is_active"])
class ModelWithRemovedField(models.Model):
name = models.CharField(max_length=64)
is_active = models.BooleanField(null=True)When you run migration (makemigrations, migrate, ...), set the environment variable DJANGO_REMOVE_FIELD_DISABLED
to not generate remove field migration.
Run all tests with make test
We need to run twice tests with different value for environment variable to be able to test the both case (using the decorator and ignoring decorator)