tivrfoa Posted May 13, 2009 Share Posted May 13, 2009 hi folks! I trying to add a foreign key constrant in the column 'disciplina_id' in the table 'teste'. mysql> desc teste; +---------------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+---------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | professor_id | int(11) | YES | MUL | NULL | | | disciplina_id | int(11) | NO | | NULL | | +---------------+---------+------+-----+---------+----------------+ 3 rows in set (0.00 sec) mysql> desc disciplina; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | disciplina | varchar(40) | YES | UNI | NULL | | +------------+-------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) mysql> alter table teste -> add foreign key (disciplina_id) references disciplina(id); ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f ails (`sgc/#sql-a8_1`, CONSTRAINT `#sql-a8_1_ibfk_1` FOREIGN KEY (`disciplina_id `) REFERENCES `disciplina` (`id`)) mysql> help meee!! =D Link to comment https://forums.phpfreaks.com/topic/157983-solved-alter-table-add-constraint/ Share on other sites More sharing options...
fenway Posted May 13, 2009 Share Posted May 13, 2009 Is there data that wold violate the constraint already in the table? Link to comment https://forums.phpfreaks.com/topic/157983-solved-alter-table-add-constraint/#findComment-833380 Share on other sites More sharing options...
tivrfoa Posted May 13, 2009 Author Share Posted May 13, 2009 Is there data that wold violate the constraint already in the table? thanks a lot!!! Link to comment https://forums.phpfreaks.com/topic/157983-solved-alter-table-add-constraint/#findComment-833483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.