Django South 从 SQLite3 架构中删除外键 REFERENCES。为什么?有问题吗?
当使用 syncdb
时,会创建以下模式:
CREATE TABLE "MyApp_supervisor" (
"id" integer NOT NULL PRIMARY KEY,
"supervisor_id" integer NOT NULL REFERENCES "MyApp_employee" ("id"),
"section_id" integer NOT NULL REFERENCES "MyApp_section" ("id")
);
当使用 migrate
时,它会更改为:
CREATE TABLE "MyApp_supervisor" (
"id" integer NOT NULL PRIMARY KEY,
"supervisor_id" integer NOT NULL,
"section_id" integer NOT NULL
);
为什么 South 这样做?我还没有注意到功能问题,但我厌倦了忽略这一点......
有人可以阐明这里发生的事情吗?
When using syncdb
the following schema is created:
CREATE TABLE "MyApp_supervisor" (
"id" integer NOT NULL PRIMARY KEY,
"supervisor_id" integer NOT NULL REFERENCES "MyApp_employee" ("id"),
"section_id" integer NOT NULL REFERENCES "MyApp_section" ("id")
);
When using migrate
, it is changed to:
CREATE TABLE "MyApp_supervisor" (
"id" integer NOT NULL PRIMARY KEY,
"supervisor_id" integer NOT NULL,
"section_id" integer NOT NULL
);
Why does South do that? I haven't noticed a functional problem yet, but I'm weary of ignoring this...
Can someone shed some light on what is happening here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为 SQLite 仅在 3.6.19 版本中引入了外键支持,如本页所述:
看起来版本 3.6.19 于 2009 年 10 月 14 日被标记,实际上相当最近,所以它可能还没有部署到所有地方。
我猜想选择不声明外键是因为它们尚未得到广泛支持,具体取决于所使用的 SQLite 版本。 (话虽这么说,以前支持外键语法,但只是忽略了。)
It's probably because foreign key support was introduced in SQLite only in version 3.6.19, as this page says:
It looks like version 3.6.19 was tagged on 14th Oct 2009, which is actually quite recent so it's probably not deployed everywhere yet.
I guess the choice was made not to declare foreign keys because they're not widely supported yet, depending on the version of SQLite used. (This being said, the foreign key syntax was supported before, but simply ignored.)