MySQL的Errno 150 [英] MySQL Errno 150

查看:129
本文介绍了MySQL的Errno 150的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一些简单的表,我不能传递这个外键错误,我不知道为什么。下面是脚本。

I'm creating a few simple tables and I can't get passed this foreign key error and I'm not sure why. Here's the script below.

create TABLE Instructors (

ID varchar(10),
First_Name varchar(50) NOT NULL,
Last_Name varchar(50) NOT NULL,
PRIMARY KEY (ID)
);

create table Courses (

Course_Code varchar(10),
Title varchar(50) NOT NULL,
PRIMARY KEY (Course_Code)

);


create table Sections (
Index_No int,
Course_Code varchar(10),
Instructor_ID varchar(10),
PRIMARY KEY (Index_No),
FOREIGN KEY (Course_Code) REFERENCES Courses(Course_Code)
    ON DELETE cascade
    ON UPDATE cascade,
FOREIGN KEY (Instructor_ID) REFERENCES Instructors(ID)
    ON DELETE set default

);




错误代码:1005.无法创建表'336_project.sections '(errno:150)

Error Code: 1005. Can't create table '336_project.sections' (errno: 150)

我的数据类型似乎是相同的,语法看起来正确。任何人都可以指出我不在这里看到什么?

My data types seem identical and the syntax seems correct. Can anyone point out what I'm not seeing here?

我正在使用MySQL Workbench 5.2

I'm using MySQL Workbench 5.2

推荐答案

重新使用InnoDB引擎, ON DELETE SET DEFAULT 是你的问题。这里是手册的摘录:

If you're using the InnoDB engine, the ON DELETE SET DEFAULT is your problem. Here's an excerpt from the manual:



虽然MySQL服务器允许SET DEFAULT,但它被拒绝InnoDB无效。使用此子句的CREATE TABLE和ALTER TABLE语句不允许用于InnoDB表。

While SET DEFAULT is allowed by the MySQL Server, it is rejected as invalid by InnoDB. CREATE TABLE and ALTER TABLE statements using this clause are not allowed for InnoDB tables.


您可以使用 ON DELETE CASCADE ON DELETE SET NULL ,但不是 ON DELETE SET DEFAULT 此处有更多信息。

You can use ON DELETE CASCADE or ON DELETE SET NULL, but not ON DELETE SET DEFAULT. There's more information here.

这篇关于MySQL的Errno 150的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆