Sunday, January 16, 2022

[FIXED] phpmyadmin mysql foreign key

Issue

phpmyadmin version: 4.1.14

db engine: InnoDB

index already set:

ALTER TABLE `tbl_name` ADD INDEX( `user_id`);

My query:

ALTER TABLE `tbl_name` ADD  FOREIGN KEY (`user_id`) REFERENCES `<db_name>`.`user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;

but im still got error:

#1215 - Impossible d'ajouter des contraintes d'index externe

In mysql documentation this error:

Erreur: 1215 SQLSTATE: HY000 (ER_CANNOT_ADD_FOREIGN)

whats wrong and what i must do for solve this? Maybe i forgot something in phpmyadmin settings? enter image description here

enter image description here

enter image description here

enter image description here


Solution

Problem solved, im add UNSIGNED to indexed column (for user_id )

`user_id` INT UNSIGNED NOT NULL ,

I think, fields with relations must have same properties



Answered By - WebArtisan

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.