“SQLSTATE[23000]:违反完整性约束"具有有效约束

quot;SQLSTATE[23000]: Integrity constraint violationquot; with valid constraint(“SQLSTATE[23000]:违反完整性约束具有有效约束)

本文介绍了“SQLSTATE[23000]:违反完整性约束"具有有效约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Symfony 2 和 Doctrine.

I'm using Symfony 2 with Doctrine.

我有 4 个班级:Country、District、County 和 Local.District 有 Country 的外键;县有区外;Local 具有 District 的外键.

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]:违反完整性约束"具有有效约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:“SQLSTATE[23000]:违反完整性约束"具有有效约束