﻿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
1892	The sqilite backend fails to mark fields as foreign keys	anonymous	Adrian Holovaty	"The sqlite table creation backend appears to only include the REFERENCES table (key) SQL if the table being referenced has a name that appears alphabetically before the table with the foreign key reference. An example; a model such as this:

{{{
#!python
from django.db import models

# Create your models here.

class Alpha(models.Model):
    name = models.CharField(50)

class Gamma(models.Model):
    name = models.CharField(50)

class Beta(models.Model):
    name = models.CharField(50)
    alpha = models.ForeignKey(Alpha)    
    gamma = models.ForeignKey(Gamma)    
}}}

Produces this sql:

{{{
#!sql
BEGIN;
CREATE TABLE ""sqlite_test_alpha"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(None) NOT NULL
);
CREATE TABLE ""sqlite_test_beta"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(None) NOT NULL,
    ""alpha_id"" integer NOT NULL REFERENCES ""sqlite_test_alpha"" (""id""),
    ""gamma_id"" integer NOT NULL
);
CREATE TABLE ""sqlite_test_gamma"" (
    ""id"" integer NOT NULL PRIMARY KEY,
    ""name"" varchar(None) NOT NULL
);
-- The following references should be added but depend on non-existant tables:
COMMIT;
}}}

Observe that `gamma_id` in the beta table lacks a REFERENCE.

I don't know enough about sqlite to know if this actually matters, but it does defy my expectations of what a foreign key field ought to be defined as. 

Past my bed time now, but I'll look into the documentation and code tomorrow, and see if I can come up with a patch."	defect	closed	Database layer (models, ORM)	dev	major	invalid		jwm@…	Unreviewed	0	0	0	0	0	0
