php - Why won't my foreign key create in MySQL? -



php - Why won't my foreign key create in MySQL? -

i've tried many different ways create table foreign key , trying insert phpmyadmin. however, not working expected.

here i've far:

create table user ( user_id bigint(10) unsigned auto_increment primary key, user_name varchar(50) not null, user_password varchar(50) not null);

this works fine. however, if seek add together table foreign key thus, refuses create:

create table article ( article_id int(20) unsigned auto_increment primary key, article_title varchar(100) not null, article_content varchar(1000) not null, user_id int(10) not null, foreign key (user_id) references user (user_id));

this not work expected , not add together table mysql database. error:

cannot add together foreign key constraint

how can prepare it?

we discovered in comments if primary key defined thus:

user_id bigint(10) unsigned

then foreign key not work, since needs match on signedness (and think type too):

user_id int(10) not null

this works fine:

user_id bigint(10) unsigned not null

here's fiddle demonstrate working.

php mysql database phpmyadmin

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -