Opened 19 years ago
Closed 19 years ago
#1892 closed defect (invalid)
The sqilite backend fails to mark fields as foreign keys
| Reported by: | anonymous | Owned by: | Adrian Holovaty |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | major | Keywords: | |
| Cc: | jwm@… | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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:
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:
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.
Change History (3)
comment:1 by , 19 years ago
| Cc: | added |
|---|
comment:2 by , 19 years ago
comment:3 by , 19 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Marking as invalid. See previous comment.
Sorry, but sqlite does not enforce foreign keys at all, see http://www.sqlite.org/omitted.html
quoting: