mysql - #1005 - Cant create table... (errno: 150) -
i have primary keys , drop tables in correct order.
i want stockid foreign key in refund table.
my schema looks this...
create table refunds ( refundid smallint auto_increment, stockid smallint, refunddate date, foreign key (stockid) references tblstock(stockid), primary key (refundid) ); create table tblstock ( stockid smallint auto_increment, stockname varchar(60), stocknumbers smallint );
when referencing table foreign key reference, table needs exist. and, column being referenced should primary key. try this:
create table tblstock ( stockid smallint auto_increment primary key, stockname varchar(60), stocknumbers smallint ); create table refunds ( refundid smallint auto_increment, stockid smallint, refunddate date, foreign key (stockid) references tblstock(stockid), primary key (refundid) );
Comments
Post a Comment