问题描述
我将Symfony 2与Doctrine结合使用。
I'm using Symfony 2 with Doctrine.
我有4个班级:国家,地区,县和地方。区具有国家/地区的外键;县有外国区;本地具有区的外键。
I have 4 classes: Country, District, County and Local. District has a foreign key of Country; County has a foreign of District; Local has a foreign key of District.
问题是,在插入县(使用数据固定装置)时,出现错误
The problem is that when inserting a County (using data fixtures), I get the error
SQLSTATE[23000]: Integrity constraint violation:
我转储了SQL以创建表和约束,并得到了以下信息:
I dumped the SQL to create the tables and constraints and got this:
CREATE TABLE Country (id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
insertedAt DATETIME NOT NULL,
flag LONGTEXT DEFAULT NULL COMMENT '(DC2Type:object)',
PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE County (id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
insertedAt DATETIME NOT NULL,
insertedBy INT NOT NULL,
idDistrict INT NOT NULL,
INDEX IDX_5F4EFA13438082DC (insertedBy),
INDEX IDX_5F4EFA1362627EDC (idDistrict),
PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE District (id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
insertedAt DATETIME NOT NULL,
insertedBy INT NOT NULL,
idCountry INT NOT NULL,
INDEX IDX_C8B736D1438082DC (insertedBy),
INDEX IDX_C8B736D143CAA294 (idCountry),
PRIMARY KEY(id)) ENGINE = InnoDB;
CREATE TABLE LOCAL (id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
insertedAt DATETIME NOT NULL,
insertedBy INT NOT NULL,
idCounty INT NOT NULL,
INDEX IDX_4A17A7EC438082DC (insertedBy),
INDEX IDX_4A17A7EC3BF357BF (idCounty),
PRIMARY KEY(id)) ENGINE = InnoDB;
ALTER TABLE County ADD CONSTRAINT FK_5F4EFA13438082DC
FOREIGN KEY (insertedBy) REFERENCES Account(id);
ALTER TABLE County ADD CONSTRAINT FK_5F4EFA1362627EDC
FOREIGN KEY (idDistrict) REFERENCES District(id);
ALTER TABLE District ADD CONSTRAINT FK_C8B736D1438082DC
FOREIGN KEY (insertedBy) REFERENCES Account(id);
ALTER TABLE District ADD CONSTRAINT FK_C8B736D143CAA294
FOREIGN KEY (idCountry) REFERENCES Country(id);
ALTER TABLE LOCAL ADD CONSTRAINT FK_4A17A7EC438082DC
FOREIGN KEY (insertedBy) REFERENCES Account(id);
ALTER TABLE LOCAL ADD CONSTRAINT FK_4A17A7EC3BF357BF
FOREIGN KEY (idCounty) REFERENCES County(id);
问题不在于DataFixture本身,因为我试图使用PhpMyAdmin插入一个县并得到相同的结果错误。
The problem is not in the DataFixture itself because I tried to insert a County using PhpMyAdmin and got the same error.
所有表都是在InnoDB引擎中创建的,我可以成功创建一个国家和地区。该错误仅在县实体中出现。
All tables are created in InnoDB engine and I can successfully create a Country and a District. The error occurs only with the County entity.
谢谢
推荐答案
安装了MAMP Pro,并一一安装了apache,mysql和php。同一项目在这种新环境下工作
Unistalled MAMP Pro and installed apache, mysql and php one by one. Same project worked under this new environment
这篇关于“ SQLSTATE [23000]:违反完整性约束”具有有效约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!