﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
27372	inspectdb fails to inspect sqlite3 tables with foreign keys that have spaces	samuller	Tim Graham <timograham@…>	"Running `python manage.py inspectdb` on an sqlite3 database with the following schema:

{{{#!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.
"	Bug	closed	Core (Management commands)	1.10	Normal	fixed			Ready for checkin	1	0	0	0	0	0
