@@ -54,15 +54,27 @@ def test_migrations_okay(*args, **kwargs):
5454            app_config  =  apps .get_app_config (app )
5555        except  LookupError :
5656            raise  RuntimeError (f'App { app }   is present in the recorded migrations but not installed, perhaps you need --create-db?' )
57-         for  path  in  os .listdir (os .path .join (app_config .path , 'migrations' )):
58-             if  re .match (r'^\d{4}_.*.py$' , path ):
59-                 disk_steps [app ].add (path .rsplit ('.' )[0 ])
57+ 
58+         migration_module  =  app_config .module .migrations 
59+         for  step  in  dir (migration_module ):
60+             if  not  step .startswith ('00' ):
61+                 continue 
62+             step_module  =  getattr (migration_module , step )
63+             migration_name  =  step_module .__name__ .rsplit ('.' )[- 1 ]
64+             disk_steps [app ].add (migration_name )
65+ 
66+             migration_cls  =  step_module .Migration 
67+             for  replaces_app_name , replaces_migration_name  in  getattr (migration_cls , 'replaces' , []):
68+                 disk_steps [app ].add (replaces_migration_name )
69+ 
6070    db_steps  =  defaultdict (set )
6171    for  record  in  MigrationRecorder .Migration .objects .only ('app' , 'name' ):
6272        if  record .app  in  app_exceptions :
6373            continue 
6474        app_name  =  app_exceptions .get (record .app , record .app )
6575        db_steps [app_name ].add (record .name )
76+ 
77+ 
6678    for  app  in  disk_steps :
6779        assert  disk_steps [app ] ==  db_steps [app ], f'Migrations not expected for app { app }  , perhaps you need --create-db?' 
6880
0 commit comments