11
11
ConnectionHandler , DatabaseError , connection , connections , models ,
12
12
)
13
13
from django .db .backends .base .schema import BaseDatabaseSchemaEditor
14
- from django .db .migrations .exceptions import (
15
- InconsistentMigrationHistory , MigrationSchemaMissing ,
16
- )
14
+ from django .db .migrations .exceptions import InconsistentMigrationHistory
17
15
from django .db .migrations .recorder import MigrationRecorder
18
16
from django .test import override_settings
19
17
@@ -697,35 +695,35 @@ def test_makemigrations_consistency_checks_respect_routers(self):
697
695
The history consistency checks in makemigrations respect
698
696
settings.DATABASE_ROUTERS.
699
697
"""
700
- def patched_ensure_schema (migration_recorder ):
698
+ def patched_has_table (migration_recorder ):
701
699
if migration_recorder .connection is connections ['other' ]:
702
- raise MigrationSchemaMissing ( 'Patched ' )
700
+ raise Exception ( 'Other connection ' )
703
701
else :
704
702
return mock .DEFAULT
705
703
706
704
self .assertTableNotExists ('migrations_unicodemodel' )
707
705
apps .register_model ('migrations' , UnicodeModel )
708
706
with mock .patch .object (
709
- MigrationRecorder , 'ensure_schema ' ,
710
- autospec = True , side_effect = patched_ensure_schema ) as ensure_schema :
707
+ MigrationRecorder , 'has_table ' ,
708
+ autospec = True , side_effect = patched_has_table ) as has_table :
711
709
with self .temporary_migration_module () as migration_dir :
712
710
call_command ("makemigrations" , "migrations" , verbosity = 0 )
713
711
initial_file = os .path .join (migration_dir , "0001_initial.py" )
714
712
self .assertTrue (os .path .exists (initial_file ))
715
- self .assertEqual (ensure_schema .call_count , 1 ) # 'default' is checked
713
+ self .assertEqual (has_table .call_count , 1 ) # 'default' is checked
716
714
717
715
# Router says not to migrate 'other' so consistency shouldn't
718
716
# be checked.
719
717
with self .settings (DATABASE_ROUTERS = ['migrations.routers.TestRouter' ]):
720
718
call_command ('makemigrations' , 'migrations' , verbosity = 0 )
721
- self .assertEqual (ensure_schema .call_count , 2 ) # 'default' again
719
+ self .assertEqual (has_table .call_count , 2 ) # 'default' again
722
720
723
721
# With a router that doesn't prohibit migrating 'other',
724
722
# consistency is checked.
725
723
with self .settings (DATABASE_ROUTERS = ['migrations.routers.EmptyRouter' ]):
726
- with self .assertRaisesMessage (MigrationSchemaMissing , 'Patched ' ):
724
+ with self .assertRaisesMessage (Exception , 'Other connection ' ):
727
725
call_command ('makemigrations' , 'migrations' , verbosity = 0 )
728
- self .assertEqual (ensure_schema .call_count , 4 ) # 'default' and 'other'
726
+ self .assertEqual (has_table .call_count , 4 ) # 'default' and 'other'
729
727
730
728
# With a router that doesn't allow migrating on any database,
731
729
# no consistency checks are made.
@@ -741,7 +739,7 @@ def patched_ensure_schema(migration_recorder):
741
739
self .assertIn (connection_alias , ['default' , 'other' ])
742
740
# Raises an error if invalid app_name/model_name occurs.
743
741
apps .get_app_config (app_name ).get_model (call_kwargs ['model_name' ])
744
- self .assertEqual (ensure_schema .call_count , 4 )
742
+ self .assertEqual (has_table .call_count , 4 )
745
743
746
744
def test_failing_migration (self ):
747
745
# If a migration fails to serialize, it shouldn't generate an empty file. #21280
0 commit comments