mirror of
https://github.com/django/django.git
synced 2025-08-31 15:57:45 +00:00
Fixed #27507 -- Used SchemaEditor.execute() to run deferred_sql in migrate's sync_apps().
This commit is contained in:
parent
71609a5b90
commit
8eb56f3c78
4 changed files with 27 additions and 2 deletions
|
@ -12,6 +12,7 @@ from django.core.management import CommandError, call_command
|
|||
from django.db import (
|
||||
ConnectionHandler, DatabaseError, connection, connections, models,
|
||||
)
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.migrations.exceptions import (
|
||||
InconsistentMigrationHistory, MigrationSchemaMissing,
|
||||
)
|
||||
|
@ -461,6 +462,20 @@ class MigrateTests(MigrationTestBase):
|
|||
# to avoid problems in subsequent tests.
|
||||
del apps._pending_operations[('migrations', 'tribble')]
|
||||
|
||||
@override_settings(INSTALLED_APPS=['migrations.migrations_test_apps.unmigrated_app_syncdb'])
|
||||
def test_migrate_syncdb_deferred_sql_executed_with_schemaeditor(self):
|
||||
"""
|
||||
For an app without migrations, editor.execute() is used for executing
|
||||
the syncdb deferred SQL.
|
||||
"""
|
||||
with mock.patch.object(BaseDatabaseSchemaEditor, 'execute') as execute:
|
||||
call_command('migrate', run_syncdb=True, verbosity=0)
|
||||
create_table_count = len([call for call in execute.mock_calls if 'CREATE TABLE' in str(call)])
|
||||
self.assertEqual(create_table_count, 2)
|
||||
# There's at least one deferred SQL for creating the foreign key
|
||||
# index.
|
||||
self.assertGreater(len(execute.mock_calls), 2)
|
||||
|
||||
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_squashed"})
|
||||
def test_migrate_record_replaced(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue