Please wait...

keyboard_arrow_up

Get all django remaining migrations in list

by in Python

It will return list of all remaining migrations in django project

from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.executor import MigrationExecutor

def get_remaining_migrations():
    connection = connections[DEFAULT_DB_ALIAS]
    connection.prepare_database()
    executor = MigrationExecutor(connection)
    targets = executor.loader.graph.leaf_nodes()
    migrations= executor.migration_plan(targets)
    return migrations