1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #29808 -- Fixed initial migration detection when identifiers are case-insensitive.

Thanks Simon Charette for the review.
This commit is contained in:
Hasan Ramezani
2019-11-14 23:18:32 +01:00
committed by Mariusz Felisiak
parent d0c86a1df4
commit 530dd193f2
6 changed files with 95 additions and 4 deletions

View File

@@ -329,8 +329,11 @@ class MigrationExecutor:
apps = after_state.apps
found_create_model_migration = False
found_add_field_migration = False
fold_identifier_case = self.connection.features.ignores_table_name_case
with self.connection.cursor() as cursor:
existing_table_names = set(self.connection.introspection.table_names(cursor))
if fold_identifier_case:
existing_table_names = {name.casefold() for name in existing_table_names}
# Make sure all create model and add field operations are done
for operation in migration.operations:
if isinstance(operation, migrations.CreateModel):
@@ -341,7 +344,10 @@ class MigrationExecutor:
model = global_apps.get_model(model._meta.swapped)
if should_skip_detecting_model(migration, model):
continue
if model._meta.db_table not in existing_table_names:
db_table = model._meta.db_table
if fold_identifier_case:
db_table = db_table.casefold()
if db_table not in existing_table_names:
return False, project_state
found_create_model_migration = True
elif isinstance(operation, migrations.AddField):
@@ -358,7 +364,10 @@ class MigrationExecutor:
# Handle implicit many-to-many tables created by AddField.
if field.many_to_many:
if field.remote_field.through._meta.db_table not in existing_table_names:
through_db_table = field.remote_field.through._meta.db_table
if fold_identifier_case:
through_db_table = through_db_table.casefold()
if through_db_table not in existing_table_names:
return False, project_state
else:
found_add_field_migration = True
@@ -368,7 +377,12 @@ class MigrationExecutor:
table,
)
for column in columns:
if column.name == field.column:
field_column = field.column
column_name = column.name
if fold_identifier_case:
column_name = column_name.casefold()
field_column = field_column.casefold()
if column_name == field_column:
found_add_field_migration = True
break
else: