繁体   English   中英

从myISAM转换为innodb的MySQL错误

[英]Mysql error with converting from myISAM to innodb

大家好,我收到此错误。

   Error 1452 : Cannot add or update a child row: a foreign key constraint fails (`s2794971db/ProfileInterests`, CONSTRAINT `ProfileInterests_ibfk_2` FOREIGN KEY (`InterestID`) REFERENCES `Interests` (`ID`))

我将表从myISAM更改为innodb ...发现我需要这样做,这样删除起来更容易。

我遇到了问题,因此删除了与之建立关系所需的表。

然后我又做到了

我原来有

create table if not exists Users (
  ID int not null auto_increment primary key,
  FirstName varchar(40) not null,
  LastName varchar(40) not null,
  UserName varchar(40) not null,
  UserEmail varchar(40) not null,
  UserDOB timestamp not null,
  UserJoin datetime not null
);

create table if not exists Interests(
    ID int not null auto_increment primary key,
    Interests varchar(40) not null
);

create table if not exists ProfileInterests (
    userID int not null References Users(ID),
    InterestID int not null References Interests(ID),
    MiddleID int not null auto_increment primary key
);

但后来我删除了最后一张桌子

create table if not exists ProfileInterests (
    userID int not null,
    InterestID int not null,
    MiddleID int not null auto_increment primary key
);

然后我将userID和InterestID放入索引中,然后为UserID添加了一个User-> ID以及对InterestID添加了一个Interest-> ID

当我尝试通过php表单输入数据时,发生错误。

任何想法...真的需要帮助!

显然,您试图将一条记录插入到ProfileInterests ,而在Interests表中没有匹配的记录。 查看确切的插入查询,并检查您是否为表中的每个字段提供有效值,这是外键关系的一部分。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM