0

我已经仔细检查了我的模式,它的正确性......事实上的原则也建立了一次......现在它的一些 FK 关系困扰着我......我也检查了数据类型。都是 int(4) 或 int(2)

这里有 2 个问题: 1. 表可以拥有的关系(依赖项/FK)数量是否有上限?我在一个表中最多有 7 个 FK 2. 引用父表 (PK) 的表的数量是否有上限?我在 20 个表中最多有 30 个字段引用选项表 3 中的单个 ID 列。是否需要定义 CASCASE 行为?我没用过!

在这种情况下,没有关系生活会更好吗?

错误是:

 SQLSTATE[HY000]: General error: 1005 Can't create table 'sokidb.#sql-268_1d' (errno: 121). Failing Query: "ALTER TABLE Acc_Gl_Accounts ADD CONSTRAINT Acc_Gl_Accounts_society_id_Soc_Societies_id FOREIGN KEY (society_id) REFERENCES Soc_Societies(id)". Failing Query: ALTER TABLE Acc_Gl_Accounts ADD CONSTRAINT Acc_Gl_Accounts_society_id_Soc_Societies_id FOREIGN KEY (society_id) REFERENCES Soc_Societies(id)  

我还直接在 MySQL 中触发了查询,它导致了同样的错误。

4

2 回答 2

1

各位,在过去的几天里,我意识到 Doctrine 可能没有已知问题。

我的错误是我在一个表'unsigned:true'中为我的键定义了一个选项,并且没有为FK定义重复相同的选项:(都是我的错,但解决方案是仔细检查你的数据类型。

调试 MySQL 相关错误的最佳方法是检查生成的 SQL 脚本。您可以轻松发现列定义的差异。

谢谢约翰,你的兴趣。

于 2010-06-23T15:01:40.323 回答
1

您可能正在使用 INNODB 表,这是现代 mysql 版本的默认值,并且遇到外键约束错误。在此处阅读完整的请求列表。

Corresponding columns in the foreign key and the referenced key must have similar internal data types inside InnoDB so that they can be compared without a type conversion. The size and sign of integer types must be the same. The length of string types need not be the same. For nonbinary (character) string columns, the character set and collation must be the same.

于 2011-05-01T09:47:15.093 回答