Skip to content
Advertisement

How to list applied migrations from command line?

I had run makemigrations and after that migrate to apply the migration

JavaScript

How to find out models in boards from command line?

Advertisement

Answer

You’ll need to use some undocumented APIs for this, but here’s one way:

JavaScript

After this, loader.disk_migrations will be a dictionary whose keys are (app_name, migration_name) tuples, and whose values are the Migration objects. So iterating loader.disk_migrations.keys() will give you a list close to what you want, and you can just format it as desired.

If you want only the ones that have been applied:

JavaScript

And then access recorder.applied_migrations()

If you want to learn a lot about how migrations work internally, and how Django figures out what migrations you have and which are applied, check out the source code of the manage.py migrate command.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement