Opened 13 years ago
Closed 13 years ago
#19677 closed Bug (fixed)
SQLite can't introspect recursive fks
| Reported by: | Simon Charette | Owned by: | Aymeric Augustin |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
SQLite's get_key_columns relies on the presence of inline REFERENCES clauses in table definitions to work properly.
However, since those are not created by BaseDatabaseCreation.sql_for_inline_foreign_key_references for recursive fks and there's no support for foreign keys on SQLite yet, sql_for_pending_references does nothing.
I'm attaching a patch that makes sure to add references on table creation with introspection assertions. It passes on all elements of product(['Python 2.7.3 ', 'Python 3.2.3 '], ['SQLite3', 'Postgresql 9.1'])
I stumbled upon this issue while trying to write tests for #19676 under a TestCase which @skipUnlessDBFeature('can_introspect_foreign_keys').
Attachments (1)
Change History (4)
by , 13 years ago
| Attachment: | 0001-Fixed-19677-Create-inline-references-for-recursive-f.patch added |
|---|
comment:1 by , 13 years ago
| Component: | ORM aggregation → Database layer (models, ORM) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
I'll update the test and commit the patch.
comment:3 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Tests don't pass out of the box but it appears to be a simple ordering issue:
(django-dev)myk@mYk tests % PYTHONPATH=.. python runtests.py --settings=test_mysql_local inspectdb introspection ~/Documents/dev/django/tests Creating test database for alias 'default'... Creating test database for alias 'other'... ........F.......s.. ====================================================================== FAIL: test_get_key_columns (regressiontests.introspection.tests.IntrospectionTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 873, in skip_wrapper return test_func(*args, **kwargs) File "/Users/myk/Documents/dev/django/tests/regressiontests/introspection/tests.py", line 117, in test_get_key_columns ('response_to_id', Article._meta.db_table, 'id')]) AssertionError: Lists differ: [(u'response_to_id', u'introsp... != [(u'reporter_id', u'introspect... First differing element 0: (u'response_to_id', u'introspection_article', u'id') (u'reporter_id', u'introspection_reporter', u'id') + [(u'reporter_id', u'introspection_reporter', u'id'), - [(u'response_to_id', u'introspection_article', u'id'), ? ^ ^ + (u'response_to_id', u'introspection_article', u'id')] ? ^ ^ - (u'reporter_id', u'introspection_reporter', u'id')] ---------------------------------------------------------------------- Ran 19 tests in 0.226s FAILED (failures=1, skipped=1) Destroying test database for alias 'default'... Destroying test database for alias 'other'...