百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

django-deprecate-fields

> 编程语言
开源

此包允许淘汰模型字段,并以向后兼容的方式删除这些字段。

196 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

此包允许淘汰模型字段,并以向后兼容的方式删除这些字段。

Django - Deprecate Field

Installation

bash
pip install django-deprecate-fields

Usage

Assume the simple following model:

python
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:

python
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:

python
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:

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

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

bash
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.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言