2009-11-19 2 views
0

Lorsque j'exécute la requête en dessous renvoie une erreur,MYSQL - ne peut pas être en mesure de créer étrangère clé

alter table `ttis`.`users` 
add constraint `FK_Role_ID` FOREIGN KEY (`ROLE_ID`) REFERENCES `roles` (`ROLE_ID`) 

Erreur:

Error Code : 1005 
Can't create table 'ttis.#sql-9c_8a' (errno: 150) 
+0

Quelle version de MySQL? –

+0

pouvez vous montrer la structure de table de 2 tables, rôles et ttis –

Répondre

2

Jetez un oeil à ce poste: 13.6.4.4. FOREIGN KEY Constraints et la recherche de "150". Il est dit ici:

If you re-create a table that was dropped, it must have a definition that conforms to the foreign key constraints referencing it. It must have the right column names and types, and it must have indexes on the referenced keys, as stated earlier. If these are not satisfied, MySQL returns error number 1005 and refers to error 150 in the error message.

If MySQL reports an error number 1005 from a CREATE TABLE statement, and the error message refers to error 150, table creation failed because a foreign key constraint was not correctly formed. Similarly, if an ALTER TABLE fails and it refers to error 150, that means a foreign key definition would be incorrectly formed for the altered table. You can use SHOW ENGINE INNODB STATUS to display a detailed explanation of the most recent InnoDB foreign key error in the server.

+0

Oui, le type de champ primaire (Role_Id) est unsigned int. mais mon type de champ de clé étrangère est juste signé int. C'est le problème qui génère une erreur. Merci. – Srinivasan

Questions connexes