Django South 从 SQLite3 架构中删除外键 REFERENCES。为什么?有问题吗?

发布于 2024-09-18 16:19:37 字数 575 浏览 1 评论 0原文

当使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2024-09-25 16:19:37

这可能是因为 SQLite 仅在 3.6.19 版本中引入了外键支持,如本页所述

本文档描述了支持
对于 SQL 外键约束
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:

This document describes the support
for SQL foreign key constraints
introduced in SQLite version 3.6.19.

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文