简体   繁体   English

从myISAM转换为innodb的MySQL错误

[英]Mysql error with converting from myISAM to innodb

hey guys, i'm getting this error. 大家好,我收到此错误。

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

I change my tables from myISAM to innodb...found out I needed to so that delete was easier. 我将表从myISAM更改为innodb ...发现我需要这样做,这样删除起来更容易。

I had issues with it so I deleted the table which I needed to create the relationships with. 我遇到了问题,因此删除了与之建立关系所需的表。

Then I made it again 然后我又做到了

I originally had 我原来有

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

but then I deleted the last table and made it 但后来我删除了最后一张桌子

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

and then I made userID and InterestID into index's and then I added a relation User-> ID for userID and interests->ID for interestID 然后我将userID和InterestID放入索引中,然后为UserID添加了一个User-> ID以及对InterestID添加了一个Interest-> ID

the error occurs when i'm trying to input data into via a php form. 当我尝试通过php表单输入数据时,发生错误。

Any ideas...really need some help! 任何想法...真的需要帮助!

Obviously, you're trying to insert a record into ProfileInterests for which there is no matching record in the Interests table. 显然,您试图将一条记录插入到ProfileInterests ,而在Interests表中没有匹配的记录。 Look at the exact insert query, and check that you're supplying a valid value for every field in the table which is part of a foreign key relationship. 查看确切的插入查询,并检查您是否为表中的每个字段提供有效值,这是外键关系的一部分。

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

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