Django迁移:run_before vs dependencies

时间:2016-08-31 14:15:12

标签: django migration

我一直以为依赖关系确保我放在那里的所有迁移都在我声明的migraton之前运行。但是,今天我发现了run_before,我不确定两者之间有什么区别。在声明Django迁移时,是否可以澄清run _ beforedependencies之间的区别?

class Migration(migrations.Migration):

    dependencies = [
        ('myapp', '0123_the_previous_migration'),
    ]

   run_before = [
    ('third_party_app', '0001_do_awesome'),
   ]  

1 个答案:

答案 0 :(得分:5)

run_beforedependencies完全相反。您应将其读作“此迁移必须在这些其他迁移之前运行”。

通常,您应该使用dependencies而不是run_before。您需要run_before的一个用例是外部应用程序在某个迁移中是否存在某种依赖关系。

"Controlling the order of migrations"中也对此进行了解释。