﻿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
12210	sqlite backend: REFERENCES clause not created with quoted ForeignKey field	xicmiah@…	nobody	"When using ForeignKey field with quoted class argument, if related class is defined later in code, in SQL output, REFERENCES clause is not created for that field.

So, with this models.py:
{{{
from django.db import models

class A(models.Model):
    name = models.CharField(max_length=5)
    ref = models.ForeignKey('B')

class B(models.Model):
    name = models.CharField(max_length=5)
}}}
python manage.py sqlall writes this:
{{{
BEGIN;
CREATE TABLE ""tst_a"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(5) NOT NULL,
    ""ref_id"" integer NOT NULL
)
;
CREATE TABLE ""tst_b"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(5) NOT NULL
)
;
CREATE INDEX ""tst_a_ref_id"" ON ""tst_a"" (""ref_id"");
COMMIT;
}}}
Namely, there is no REFERENCES clause on ref_id field.

If the classes are swapped, everything is fine:
models.py:
{{{
from django.db import models

class B(models.Model):
    name = models.CharField(max_length=5)

class A(models.Model):
    name = models.CharField(max_length=5)
    ref = models.ForeignKey('B')
}}}
sqlall:
{{{
BEGIN;
CREATE TABLE ""tst_b"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(5) NOT NULL
)
;
CREATE TABLE ""tst_a"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(5) NOT NULL,
    ""ref_id"" integer NOT NULL REFERENCES ""tst_b"" (""id"")
)
;
CREATE INDEX ""tst_a_ref_id"" ON ""tst_a"" (""ref_id"");
COMMIT;
}}}
Is this behavior intended?"		closed	Database layer (models, ORM)	1.1		wontfix	ForeignKey		Unreviewed	0	0	0	0	0	0
