{{{#!sql
CREATE TABLE table_1 (
id INTEGER PRIMARY KEY AUTOINCREMENT
);
CREATE TABLE table_2 (
id INTEGER PRIMARY KEY AUTOINCREMENT,
foreign_key_col INTEGER,
FOREIGN KEY (foreign_key_col) REFERENCES table_1(id)
);
}}}
results in output missing tables with foreign keys:
{{{#!python
class Table1(models.Model):
id = models.IntegerField(primary_key=True, blank=True, null=True) #
AutoField?
class Meta:
managed = False
db_table = 'table_1'
# Unable to inspect table 'table_2'
# The error was: 'NoneType' object has no attribute 'groups'
}}}
It turns out the regular expression (in
django/db/backends/sqlite3/introspection.py) is not matching the string
"FOREIGN KEY (foreign_key_col) REFERENCES table_1(id)" due to the single
space character between KEY and the bracket. Depending on the schema input
used to create the table there could be any amount of whitespace there.
--
Ticket URL: <https://code.djangoproject.com/ticket/27372>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:1>
* component: Database layer (models, ORM) => Core (Management commands)
* needs_tests: 0 => 1
* easy: 1 => 0
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
[https://github.com/django/django/pull/7402 PR] (currently missing a test)
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:2>
* owner: nobody => Saulius Žemaitaitis
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:3>
* owner: Saulius Žemaitaitis => (none)
* status: assigned => new
* needs_tests: 1 => 0
Comment:
[https://github.com/django/django/pull/7486 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:4>
* stage: Accepted => Ready for checkin
Comment:
Patch now has a test and looks good.
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:5>
* owner: (none) => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"f28d29e8b726b8b013e8739fab542a796f348e78" f28d29e8]:
{{{
#!CommitTicketReference repository=""
revision="f28d29e8b726b8b013e8739fab542a796f348e78"
Fixed #27372 -- Fixed introspection of SQLite foreign keys with spaces in
DDL.
Thanks samuller for the report and initial patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:6>