summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/features.py7
-rw-r--r--django/db/backends/sqlite3/introspection.py14
2 files changed, 12 insertions, 9 deletions
diff --git a/django/db/backends/sqlite3/features.py b/django/db/backends/sqlite3/features.py
index 2886ecc3be..6e10e61572 100644
--- a/django/db/backends/sqlite3/features.py
+++ b/django/db/backends/sqlite3/features.py
@@ -55,6 +55,13 @@ class DatabaseFeatures(BaseDatabaseFeatures):
# Date/DateTime fields and timedeltas.
"expressions.tests.FTimeDeltaTests.test_mixed_comparisons1",
}
+ create_test_table_with_composite_primary_key = """
+ CREATE TABLE test_table_composite_pk (
+ column_1 INTEGER NOT NULL,
+ column_2 INTEGER NOT NULL,
+ PRIMARY KEY(column_1, column_2)
+ )
+ """
@cached_property
def django_test_skips(self):
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py
index a74153757b..4805305aa5 100644
--- a/django/db/backends/sqlite3/introspection.py
+++ b/django/db/backends/sqlite3/introspection.py
@@ -156,15 +156,11 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
) in cursor.fetchall()
}
- def get_primary_key_column(self, cursor, table_name):
- """Return the column name of the primary key for the given table."""
+ def get_primary_key_columns(self, cursor, table_name):
cursor.execute(
"PRAGMA table_info(%s)" % self.connection.ops.quote_name(table_name)
)
- for _, name, *_, pk in cursor.fetchall():
- if pk:
- return name
- return None
+ return [name for _, name, *_, pk in cursor.fetchall() if pk]
def _parse_column_or_constraint_definition(self, tokens, columns):
token = None
@@ -372,14 +368,14 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
if orders is not None:
constraints[index]["orders"] = orders
# Get the PK
- pk_column = self.get_primary_key_column(cursor, table_name)
- if pk_column:
+ pk_columns = self.get_primary_key_columns(cursor, table_name)
+ if pk_columns:
# SQLite doesn't actually give a name to the PK constraint,
# so we invent one. This is fine, as the SQLite backend never
# deletes PK constraints by name, as you can't delete constraints
# in SQLite; we remake the table with a new PK instead.
constraints["__primary__"] = {
- "columns": [pk_column],
+ "columns": pk_columns,
"primary_key": True,
"unique": False, # It's not actually a unique constraint.
"foreign_key": None,