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&page=Status&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 ?
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.