0

I have a table with the following

1   idssMembers int(11)         No  None    AUTO_INCREMENT  Change Change   Drop Drop   
2   ssName  varchar(45) utf8_general_ci         

I want to make a foreign key on another table in the memberId column which is:

    6   memberId    int(11)         Yes     NULL    

But I keep getting 2 different kinds of error messages. First I get:

    #1452 - Cannot add or update a child row: a foreign key constraint fails (`inter-design_net_01`.<result 2 when explaining filename '#sql-548_6e50d1'>, CONSTRAINT `memberId` FOREIGN KEY (`memberId`) REFERENCES `ssmembers` (`idssMembers`) ON DELETE CASCADE ON UPDATE C) 

the other one says something about check data types. I can't reproduce that error at the moment for the exact wording. everything is indexed and both have int(11) so I can't figure out what the probem is. if you need more details please let me know.

Kumar V
  • 8,810
  • 9
  • 39
  • 58
Phillip Perry
  • 27
  • 1
  • 1
  • 7
  • possible duplicate of [Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails](http://stackoverflow.com/questions/1253459/mysql-error-1452-cannot-add-or-update-a-child-row-a-foreign-key-constraint-fa) – Bill Karwin Mar 08 '14 at 18:47
  • Thank you for that link. That had the answer I was looking for. – Phillip Perry Mar 08 '14 at 19:30
  • Although emptying the table to create the foreign key worked for the above table. I created another table and that one is giving me Error creating foreign key on memberId (check data types). I know the data types are the same and everything is indexed. I have checked the above link and all the answers did not work for me. – Phillip Perry Mar 08 '14 at 20:17
  • I can be successful if I use a completely different constraint name. I could put dog in there and it would work. Do I need unique constraint names for every foreign key I make? – Phillip Perry Mar 08 '14 at 20:24
  • 1
    Yes, constraint names must be unique within a database. – Bill Karwin Mar 09 '14 at 02:04

0 Answers0