PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] phpmyadmin mysql foreign key

 January 16, 2022     foreign-keys, mysql, phpmyadmin     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing