1
1
from django .apps import apps
2
2
from django .core .management .base import BaseCommand , CommandError
3
3
from django .db import DEFAULT_DB_ALIAS , connections
4
- from django .db .migrations .executor import MigrationExecutor
5
- from django .db .migrations .loader import AmbiguityError
4
+ from django .db .migrations .loader import AmbiguityError , MigrationLoader
6
5
7
6
8
7
class Command (BaseCommand ):
@@ -33,8 +32,8 @@ def handle(self, *args, **options):
33
32
# Get the database we're operating from
34
33
connection = connections [options ['database' ]]
35
34
36
- # Load up an executor to get all the migration data
37
- executor = MigrationExecutor (connection )
35
+ # Load up an loader to get all the migration data
36
+ loader = MigrationLoader (connection )
38
37
39
38
# Resolve command-line arguments into a migration
40
39
app_label , migration_name = options ['app_label' ], options ['migration_name' ]
@@ -43,10 +42,10 @@ def handle(self, *args, **options):
43
42
apps .get_app_config (app_label )
44
43
except LookupError as err :
45
44
raise CommandError (str (err ))
46
- if app_label not in executor . loader .migrated_apps :
45
+ if app_label not in loader .migrated_apps :
47
46
raise CommandError ("App '%s' does not have migrations" % app_label )
48
47
try :
49
- migration = executor . loader .get_migration_by_prefix (app_label , migration_name )
48
+ migration = loader .get_migration_by_prefix (app_label , migration_name )
50
49
except AmbiguityError :
51
50
raise CommandError ("More than one migration matches '%s' in app '%s'. Please be more specific." % (
52
51
migration_name , app_label ))
@@ -61,8 +60,8 @@ def handle(self, *args, **options):
61
60
62
61
# Make a plan that represents just the requested migrations and show SQL
63
62
# for it
64
- plan = [(executor . loader .graph .nodes [target ], options ['backwards' ])]
65
- sql_statements = executor . loader .collect_sql (plan )
63
+ plan = [(loader .graph .nodes [target ], options ['backwards' ])]
64
+ sql_statements = loader .collect_sql (plan )
66
65
if not sql_statements and options ['verbosity' ] >= 1 :
67
66
self .stderr .write ('No operations found.' )
68
67
return '\n ' .join (sql_statements )
0 commit comments