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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.