Skip to main content

Django - Deprecate Field

PyPi License Contributing Stars

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)

On a ForeignKey, OneToOneField or ManyToManyField (without an explicit through model), makemigrations also drops the database foreign key constraints: once the field is deprecated, Django no longer applies its on_delete, so the constraint would otherwise make deleting a referenced row fail.

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"}

Contributing

First of all, thank you very much for contributing to this project. Please base your work on the master branch and target master in your pull request.

Running tests

Install the package in editable mode and run the test suite:

pip install -e .
./manage.py test tests --no-input

To test against a specific Python and Django version combination, use tox:

pip install tox
tox -e py313-django60

To see a coverage report:

tox -e coverage

License

django-deprecate-fields is released under the Apache 2.0 License.

Metadata

Release files for django-deprecate-fields 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-deprecate-fields 0.2.4
File Size Uploaded Provenance Actions
django_deprecate_fields-0.2.4.tar.gz 9.1 kB Without provenance Details for django_deprecate_fields-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-deprecate-fields 0.2.4
File Interpreter ABI Platform Actions
django_deprecate_fields-0.2.4-py3-none-any.whl Python 3 none any Details for django_deprecate_fields-0.2.4-py3-none-any.whl

Total release size: 17.8 kB

Release files / django_deprecate_fields-0.2.4.tar.gz

Download URL django_deprecate_fields-0.2.4.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f3ba46e1ae48b46a75a6c86502cfe72dcaa913fdb107ad255873682ab45f3d5e
BLAKE2b-256 checksum
How to use checksums
eb6d6eb924b871e78fbd11a223ee4727de62d84d391a2f9a1d2d5ac1cd7802a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / django_deprecate_fields-0.2.4-py3-none-any.whl

Download URL django_deprecate_fields-0.2.4-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
338f2166a819d934a95c6ae8f8e4c0534b7e1082d56d85689db00bbc146c610e
BLAKE2b-256 checksum
How to use checksums
56f946a8fe64243840e638f79cd9394bcd33b89a65102dd450a2d41da0b03f7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Security for django-deprecate-fields 0.2.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page