1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #29517 -- Added support for SQLite column check constraints on positive integer fields.

This commit is contained in:
Tim Graham
2018-06-22 14:42:51 -04:00
parent 7410618528
commit b9cf764be6
4 changed files with 34 additions and 2 deletions

View File

@@ -231,6 +231,32 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
one or more columns.
"""
constraints = {}
# Find inline check constraints.
try:
table_schema = cursor.execute(
"SELECT sql FROM sqlite_master WHERE type='table' and name=%s" % (
self.connection.ops.quote_name(table_name),
)
).fetchone()[0]
except TypeError:
# table_name is a view.
pass
else:
fields_with_check_constraints = [
schema_row.strip().split(' ')[0][1:-1]
for schema_row in table_schema.split(',')
if schema_row.find('CHECK') >= 0
]
for field_name in fields_with_check_constraints:
# An arbitrary made up name.
constraints['__check__%s' % field_name] = {
'columns': [field_name],
'primary_key': False,
'unique': False,
'foreign_key': False,
'check': True,
'index': False,
}
# Get the index info
cursor.execute("PRAGMA index_list(%s)" % self.connection.ops.quote_name(table_name))
for row in cursor.fetchall():