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.

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

the error occurs when i'm trying to input data into via a php form.

Any ideas...really need some help!

Upvotes: 0

Views: 205

Answers (1)

Marc B
Marc B

Reputation: 360892

Obviously, you're trying to insert a record into ProfileInterests for which there is no matching record in the Interests table. 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.

Upvotes: 1

Related Questions