Opened 9 years ago

Closed 8 years ago

#24113 closed New feature (needsinfo)

django.db.backends.sqlite3.introspection.get_constraints does not return constraint names.

Reported by: Damien Nozay Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


django.db.backends.sqlite3.introspection.get_constraints does not return constraint names.

I was trying to add a regression test for .

However the introspection does not get the constraint names properly.

Here is how you would get the equivalent of show create table in sqlite3.

            cursor.execute("SELECT sql FROM sqlite_master WHERE tbl_name = %s", [table])
            result = cursor.fetchall()[0]

e.g. this is the output for tests.schema.models.UniqueTest

[(u'CREATE TABLE "schema_uniquetest" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "year" integer NOT NULL, "slug" varchar(50) NOT NULL, CONSTRAINT "schema_uniquetest_year_4b36f60cc3fa9c74_uniq" UNIQUE ("year", "slug"))',),

vs. the output of connection.introspection.get_constraints

{'__primary__': {'check': False,
                 'columns': [u'id'],
                 'foreign_key': False,
                 'index': False,
                 'primary_key': True,
                 'unique': False},
 u'schema_uniquetest_2dbcba41': {'check': False,
                                 'columns': [u'slug'],
                                 'foreign_key': False,
                                 'index': True,
                                 'primary_key': False,
                                 'unique': False},
 u'sqlite_autoindex_schema_uniquetest_1': {'check': False,
                                           'columns': [u'year', u'slug'],
                                           'foreign_key': False,
                                           'index': True,
                                           'primary_key': False,
                                           'unique': True}}

side note: would be helpful to refactor django.db.backends.schema so that create_model uses a helper function that generates the sql statements; which whould make it possible to inspect the sql more easily in tests.

Change History (2)

comment:1 by Tim Graham, 9 years ago

Component: UncategorizedDatabase layer (models, ORM)
Triage Stage: UnreviewedAccepted
Type: UncategorizedNew feature
Version: 1.7master

comment:2 by Claude Paroz, 8 years ago

Resolution: needsinfo
Status: newclosed

I have tried a bit but was unable to reproduce that index name mismatch. Could you please provide some test case where this difference would show up?

Note: See TracTickets for help on using tickets.
Back to Top