mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #10164 -- Made AutoField increase monotonically on SQLite
Thanks malte for the report.
This commit is contained in:
@@ -23,6 +23,7 @@ class BaseDatabaseCreation(object):
|
||||
destruction of test databases.
|
||||
"""
|
||||
data_types = {}
|
||||
data_types_suffix = {}
|
||||
data_type_check_constraints = {}
|
||||
|
||||
def __init__(self, connection):
|
||||
@@ -53,6 +54,7 @@ class BaseDatabaseCreation(object):
|
||||
qn = self.connection.ops.quote_name
|
||||
for f in opts.local_fields:
|
||||
col_type = f.db_type(connection=self.connection)
|
||||
col_type_suffix = f.db_type_suffix(connection=self.connection)
|
||||
tablespace = f.db_tablespace or opts.db_tablespace
|
||||
if col_type is None:
|
||||
# Skip ManyToManyFields, because they're not represented as
|
||||
@@ -88,6 +90,8 @@ class BaseDatabaseCreation(object):
|
||||
(model, f))
|
||||
else:
|
||||
field_output.extend(ref_output)
|
||||
if col_type_suffix:
|
||||
field_output.append(style.SQL_KEYWORD(col_type_suffix))
|
||||
table_output.append(' '.join(field_output))
|
||||
for field_constraints in opts.unique_together:
|
||||
table_output.append(style.SQL_KEYWORD('UNIQUE') + ' (%s)' %
|
||||
|
||||
@@ -106,6 +106,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||
supports_check_constraints = False
|
||||
autocommits_when_autocommit_is_off = True
|
||||
supports_paramstyle_pyformat = False
|
||||
supports_sequence_reset = False
|
||||
|
||||
@cached_property
|
||||
def uses_savepoints(self):
|
||||
|
||||
@@ -34,6 +34,9 @@ class DatabaseCreation(BaseDatabaseCreation):
|
||||
'TextField': 'text',
|
||||
'TimeField': 'time',
|
||||
}
|
||||
data_types_suffix = {
|
||||
'AutoField': 'AUTOINCREMENT',
|
||||
}
|
||||
|
||||
def sql_for_pending_references(self, model, style, pending_references):
|
||||
"SQLite3 doesn't support constraints"
|
||||
|
||||
@@ -175,7 +175,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||
results = results[results.index('(') + 1:results.rindex(')')]
|
||||
for field_desc in results.split(','):
|
||||
field_desc = field_desc.strip()
|
||||
m = re.search('"(.*)".*PRIMARY KEY$', field_desc)
|
||||
m = re.search('"(.*)".*PRIMARY KEY( AUTOINCREMENT)?$', field_desc)
|
||||
if m:
|
||||
return m.groups()[0]
|
||||
return None
|
||||
|
||||
@@ -395,6 +395,9 @@ class Field(object):
|
||||
"check": check_string,
|
||||
}
|
||||
|
||||
def db_type_suffix(self, connection):
|
||||
return connection.creation.data_types_suffix.get(self.get_internal_type())
|
||||
|
||||
@property
|
||||
def unique(self):
|
||||
return self._unique or self.primary_key
|
||||
|
||||
Reference in New Issue
Block a user