mysql - Error 1215: Cannot add foreign key constraint solution? -


been wondering why still ain't able add constraint accountdetails table. tried every possible way search way same. tried checking syntax if chance wrong spelling , other stuff that. i'm using mysql

create table  personalinformation  (    username  varchar(50) not null,    lastname  varchar(50),    firstname  varchar(50),    middlename  varchar(50),    gender  char(1),    birthdate  date,    addressid  int not null,    email  varchar(50),    phonenumber  varchar(50),    homenumber  varchar(50),   primary key  ( username ) );  create table  addressinformation  (    addressid  int not null,    country  varchar(50),    zipcode  varchar(50),    state  varchar(50),    city  varchar(50),    street  varchar(50),    housenumber  varchar(50),   primary key  ( addressid ) );  create table  accountdetails  (    username  varchar(50) not null,    password  varchar(50),    timeloggedin  date,    timeloggedout  date,    roleid  varchar(50),   primary key  ( username ) );  create table  userdonation  (    username  varchar(50) not null,    donations  double,    lastdonated  date,   primary key  ( username ) );  create table  donationlog  (    donationid  int not null auto_increment,    username  varchar(50),    amount  double,    datedonated  date,   primary key  ( donationid ) );  create table  roles  (    roleid varchar(50),    role  varchar(50),    roledescription  varchar(50),   primary key  ( roleid ) );   alter table  personalinformation  add constraint  personalinformation_fk1  foreign key ( addressid ) references addressinformation( addressid ); alter table  personalinformation  add constraint  personalinformation_fk2  foreign key ( username ) references accountdetails( username ); alter table  userdonation  add constraint  userdonation_fk1  foreign key ( username ) references accountdetails( username ); alter table  donationlog  add constraint  donationlog_fk1  foreign key ( username ) references accountdetails( username ); alter table accountdetails add constraint accountdetails_fk1 foreign key (roleid) references roles( roleid ) 


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -