3

I write a query when doing a tutorial Agile web application development with yii. I was trying to alter a table with this query and got this error in phpmyadin

#1005 - Can't create table 'trackstar_dev.#sql-152_16' (errno: 121) (<a href="server_engines.php?engine=InnoDB&amp;page=Status&amp;token=af80b3320dff7dfda18d88d97fe80da4">Details...</a>)

Here is my query

ALTER TABLE `tbl_project_user_assignment` ADD CONSTRAINT `FK_project_
user` FOREIGN KEY (`project_id`) REFERENCES `tbl_project` (`id`) ON
DELETE CASCADE ON UPDATE RESTRICT

Can Anyone help please ?

Ashfaq Rahman
  • 85
  • 2
  • 5
  • 12

1 Answers1

2

This happens when table tbl_project_user_assignment has already records which project_id is not found on the table (which you want to reference) tbl_project.id. The best way you can do is to empty the tbl_project_user_assignment and alter it again to add the constraint.

John Woo
  • 258,903
  • 69
  • 498
  • 492
  • Thanks a lot for your answer. But table is already empty. I also does it again after seeing your answer. But still same issue . Any help ? :( – Ashfaq Rahman Oct 07 '12 at 07:21