Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Migrations: run_before vs dependencies

I always thought that dependencies made sure that all the migrations that I put there ran before the migraton I was declaring. However, today I found about run_before and Im not sure what are the differences between both. Can someon clarify the difference between run_before and dependencies when declaring a Django migration?

class Migration(migrations.Migration):

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

   run_before = [
    ('third_party_app', '0001_do_awesome'),
   ]  
like image 691
Pablo Estrada Avatar asked Aug 31 '16 14:08

Pablo Estrada


1 Answers

run_before is the exact opposite of dependencies. You should read it as "this migration must run before these other migrations".

Generally you should be using dependencies over run_before. One use-case where you need run_before is if an external app has a dependency in some way on one of your migrations.

This is also explained in "Controlling the order of migrations".

like image 99
knbk Avatar answered Sep 20 '22 03:09

knbk