Jump to content

[SOLVED] alter table add constraint


tivrfoa

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.