如何删除 Django 迁移文件?
How can I remove a Django migration file?
我进行了迁移,并意识到我犯了一个错误(通过添加默认值),然后我进行了一个允许 null 的新迁移。
我不希望我的同事 运行 第一次迁移将 default 值添加到数千条记录.我怎样才能在不破坏当前迁移的情况下删除该迁移(通常,如果您只是删除一个迁移,您会得到一堆很难修复的错误)。
我假设你可以使用命令?我假设它会是这样的 ~>
例如django manage.py deletemigration <migration_id>
壁球
您可以执行 ./manage.py squashmigrations,因为您的一个迁移有效地抵消了另一个迁移,最终结果将是该字段可为空。您的同事将不必完成添加默认值的步骤。
Squashing is the act of reducing an existing set of many migrations
down to one (or sometimes a few) migrations which still represent the
same changes.
编辑迁移文件
您可以手动编辑迁移文件以删除对列的更改。迁移实际上可以有一个空迁移
class Migration(migrations.Migration):
dependencies = [
(some stuff here),
]
operations = []
我进行了迁移,并意识到我犯了一个错误(通过添加默认值),然后我进行了一个允许 null 的新迁移。
我不希望我的同事 运行 第一次迁移将 default 值添加到数千条记录.我怎样才能在不破坏当前迁移的情况下删除该迁移(通常,如果您只是删除一个迁移,您会得到一堆很难修复的错误)。
我假设你可以使用命令?我假设它会是这样的 ~>
例如django manage.py deletemigration <migration_id>
壁球
您可以执行 ./manage.py squashmigrations,因为您的一个迁移有效地抵消了另一个迁移,最终结果将是该字段可为空。您的同事将不必完成添加默认值的步骤。
Squashing is the act of reducing an existing set of many migrations down to one (or sometimes a few) migrations which still represent the same changes.
编辑迁移文件
您可以手动编辑迁移文件以删除对列的更改。迁移实际上可以有一个空迁移
class Migration(migrations.Migration):
dependencies = [
(some stuff here),
]
operations = []