我一直以为依赖关系确保我放在那里的所有迁移都在我声明的migraton之前运行。但是,今天我发现了run_before,我不确定两者之间有什么区别。在声明Django迁移时,是否可以澄清run _ before
和dependencies
之间的区别?
class Migration(migrations.Migration):
dependencies = [
('myapp', '0123_the_previous_migration'),
]
run_before = [
('third_party_app', '0001_do_awesome'),
]
答案 0 :(得分:5)
run_before
与dependencies
完全相反。您应将其读作“此迁移必须在这些其他迁移之前运行”。
通常,您应该使用dependencies
而不是run_before
。您需要run_before
的一个用例是外部应用程序在某个迁移中是否存在某种依赖关系。
"Controlling the order of migrations"中也对此进行了解释。