I was trying to add a regression test for
https://github.com/django/django/pull/3862 .
However the introspection does not get the constraint names properly.
Here is how you would get the equivalent of `show create table` in
`sqlite3`.
{{{#!python
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24113>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* version: 1.7 => master
* needs_docs: => 0
* type: Uncategorized => New feature
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24113#comment:1>
* status: new => closed
* resolution: => needsinfo
Comment:
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/24113#comment:2>