Fixed #27321 -- Added detection for table case name sensitivity on MySQL.

This commit is contained in:
Adam Chainz 2016-11-28 18:29:21 +00:00 committed by Tim Graham
parent aa2cb4c622
commit 95238a7de8
6 changed files with 15 additions and 5 deletions

View File

@ -224,9 +224,9 @@ class BaseDatabaseFeatures(object):
# Defaults to False to allow third-party backends to opt-in. # Defaults to False to allow third-party backends to opt-in.
can_clone_databases = False can_clone_databases = False
# Does the backend consider quoted identifiers with different casing to # Does the backend consider table names with different casing to
# be equal? # be equal?
ignores_quoted_identifier_case = False ignores_table_name_case = False
# Place FOR UPDATE right after FROM clause. Used on MSSQL. # Place FOR UPDATE right after FROM clause. Used on MSSQL.
for_update_after_from = False for_update_after_from = False

View File

@ -375,7 +375,7 @@ class BaseDatabaseSchemaEditor(object):
Renames the table a model points to. Renames the table a model points to.
""" """
if (old_db_table == new_db_table or if (old_db_table == new_db_table or
(self.connection.features.ignores_quoted_identifier_case and (self.connection.features.ignores_table_name_case and
old_db_table.lower() == new_db_table.lower())): old_db_table.lower() == new_db_table.lower())):
return return
self.execute(self.sql_rename_table % { self.execute(self.sql_rename_table % {

View File

@ -72,3 +72,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
All storage engines except MyISAM support transactions. All storage engines except MyISAM support transactions.
""" """
return self._mysql_storage_engine != 'MyISAM' return self._mysql_storage_engine != 'MyISAM'
@cached_property
def ignores_table_name_case(self):
with self.connection.cursor() as cursor:
cursor.execute('SELECT @@LOWER_CASE_TABLE_NAMES')
result = cursor.fetchone()
return result and result[0] != 0

View File

@ -37,7 +37,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_temporal_subtraction = True supports_temporal_subtraction = True
# Oracle doesn't ignore quoted identifiers case but the current backend # Oracle doesn't ignore quoted identifiers case but the current backend
# does by uppercasing all identifiers. # does by uppercasing all identifiers.
ignores_quoted_identifier_case = True ignores_table_name_case = True
def introspected_boolean_field_type(self, field=None, created_separately=False): def introspected_boolean_field_type(self, field=None, created_separately=False):
""" """

View File

@ -33,7 +33,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
supports_sequence_reset = False supports_sequence_reset = False
can_clone_databases = True can_clone_databases = True
supports_temporal_subtraction = True supports_temporal_subtraction = True
ignores_quoted_identifier_case = True ignores_table_name_case = True
@cached_property @cached_property
def uses_savepoints(self): def uses_savepoints(self):

View File

@ -456,6 +456,9 @@ Database backend API
which is deprecated. Custom database backends should ensure all types of which is deprecated. Custom database backends should ensure all types of
indexes are returned by ``DatabaseIntrospection.get_constraints()``. indexes are returned by ``DatabaseIntrospection.get_constraints()``.
* Renamed the ``ignores_quoted_identifier_case`` feature to
``ignores_table_name_case`` to more accurately reflect how it is used.
Dropped support for PostgreSQL 9.2 and PostGIS 2.0 Dropped support for PostgreSQL 9.2 and PostGIS 2.0
-------------------------------------------------- --------------------------------------------------