1. 程式人生 > >mysql建表語句以及新增外來鍵報1215錯誤

mysql建表語句以及新增外來鍵報1215錯誤

其中外來鍵錯誤解決辦法:

保證外建的主表字段和子表字段型別和長度要一致

SET foreign_key_checks=0;
drop table if exists feedrice;

/*==============================================================*/
/* Table: FeedRice                                              */
/*==============================================================*/
create table feedrice
(
   ID                   int not null auto_increment,
   ORG_ID               smallint(6),
   OCCUR_DATE           date,
   BUILD_NUM            smallint,
   FEED                 int,
   RICE                 int,
   CREATE_DT            datetime,
   UPDATE_DT            datetime,
   primary key (ID)
);

alter table feedrice add constraint FK_Reference_154 foreign key (ORG_ID)
      references organize (ID) on delete restrict on update restrict;

SET foreign_key_checks=1;