summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3/introspection.py
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2018-09-12 23:45:17 +0100
committerTim Graham <timograham@gmail.com>2019-01-09 09:59:15 -0500
commita35d2a4510d5beec398b1007aaa26492d6aedf97 (patch)
treef21fd8cfc51a2a19370a1f3283e53f4cbef87553 /django/db/backends/sqlite3/introspection.py
parente7f0e9b7045e7bcbe1e8ad85aec486c01f570e43 (diff)
downloaddjango-a35d2a4510d5beec398b1007aaa26492d6aedf97.tar.gz
Refs #23748 -- Added AutoField introspection for SQLite.
Diffstat (limited to 'django/db/backends/sqlite3/introspection.py')
-rw-r--r--django/db/backends/sqlite3/introspection.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index 8ed043ba67..490606c64d 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -1,12 +1,15 @@
import re
+from collections import namedtuple
import sqlparse
from django.db.backends.base.introspection import (
- BaseDatabaseIntrospection, FieldInfo, TableInfo,
+ BaseDatabaseIntrospection, FieldInfo as BaseFieldInfo, TableInfo,
)
from django.db.models.indexes import Index
+FieldInfo = namedtuple('FieldInfo', BaseFieldInfo._fields + ('pk',))
+
field_size_re = re.compile(r'^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$')
@@ -57,6 +60,14 @@ class FlexibleFieldLookupDict:
class DatabaseIntrospection(BaseDatabaseIntrospection):
data_types_reverse = FlexibleFieldLookupDict()
+ def get_field_type(self, data_type, description):
+ field_type = super().get_field_type(data_type, description)
+ if description.pk and field_type in {'BigIntegerField', 'IntegerField'}:
+ # No support for BigAutoField as SQLite treats all integer primary
+ # keys as signed 64-bit integers.
+ return 'AutoField'
+ return field_type
+
def get_table_list(self, cursor):
"""Return a list of table and view names in the current database."""
# Skip the sqlite_sequence system table used for autoincrement key
@@ -82,6 +93,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
None,
info['null_ok'],
info['default'],
+ info['pk'] == 1,
) for info in self._table_info(cursor, table_name)
]