Jump to content

Help: MySQL foreign key error

Go to solution Solved by Djeunut,

We found the issue, there was a problem with the naming since it can't have the same name as another foreign key and the table had to be empty for some reason.

I'm trying to make a foreign key but MySQL keeps telling me there is a duplicate key and I have no clue why or where there is a duplicate.

Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `stemmy`.`stemmen` 
ADD CONSTRAINT `idPartij`
  FOREIGN KEY (`idPartij`)
  REFERENCES `stemmy`.`partijen` (`idPartij`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;

ERROR 1005: Can't create table `stemmy`.`stemmen` (errno: 121 "Duplicate key on write or update")
SQL Statement:
ALTER TABLE `stemmy`.`stemmen` 
ADD CONSTRAINT `idPartij`
  FOREIGN KEY (`idPartij`)
  REFERENCES `stemmy`.`partijen` (`idPartij`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION

 

Link to comment
Share on other sites

Link to post
Share on other sites

We found the issue, there was a problem with the naming since it can't have the same name as another foreign key and the table had to be empty for some reason.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×