问题描述
- 数据库foreign key error 1215
-
create table department(dept_name varchar(20) not null primary key building varchar(20)budget numeric(122)); create table instructor( ID varchar(5) name varchar(20) dept_name varchar(20) salary numeric(121));create table course( course_id varchar(8) title varchar(50) dept_name varchar(20) references department credits numeric(20) primary key (course_id) #foreign key constraints can be here too : #foreign key (dept_name) references department);/*alter table course change column course_id course_id varchar(8) unique;*/create table section( course_id varchar(8) sec_id varchar(8) semster varchar(6) year numeric(40) building varchar(15) room_number varchar(7) time_sloth_id varchar(4) primary key(course_idsemsteryear) foreign key (course_id) references course);create table teach( ID varchar(5) course_id varchar(8) semster varchar(6) year numeric(40) primary key (IDcourse_idsemster year) foreign key (ID) references instructor foreign key (course_id semster year) references section);
这段代码运行在MySql上总是在create table section的时候报error 1215不能添加外键......求问为什么啊......
解决方案
试试foreign key (course_id) references course(course_id)
?
时间: 2024-09-30 02:04:32