0

I cannot alter my table:

ALTER TABLE `Account` ADD FOREIGN KEY ( `pid` ) REFERENCES `mydb`.`Person` (
`pid`) ON DELETE RESTRICT ON UPDATE RESTRICT ;

getting error like

SQL error #1452 - Cannot add or update a child row: a foreign key constraint fails (`mydb`.`#sql-d64_8a`, CONSTRAINT `#sql-d64_8a_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `Person` (`pid`))

Any ideas

Mr. Radical
  • 1,847
  • 1
  • 19
  • 29
Akhila
  • 1
  • 1
  • 2
    You must match the fields you're using for the constraint exactly in size and type. If you have data that fails the constraint already in your table you'll have to fix that first or the constraint can't be applied. –  Feb 13 '14 at 05:02
  • everything is matched. then also getting same error – Akhila Feb 13 '14 at 05:07
  • Seems you have some data in your pid which are not in you primary table, first remove those records and then this constraints will be created. – Ali Adravi Feb 13 '14 at 05:27

0 Answers0