简体   繁体   English

错误1005(HY000):无法创建表carparkful。#sql-3b64_3(错误号:150“外键约束格式不正确”)

[英]ERROR 1005 (HY000): Can't create table `carparkful`.`#sql-3b64_3` (errno: 150 “Foreign key constraint is incorrectly formed”)

CREATE TABLE user
(userid INT(10), uname VARCHAR(30) NOT NULL, phone_num VARCHAR(10) NOT NULL, car_plate VARCHAR(9) NOT NULL,
PRIMARY KEY (userid));

INSERT INTO user (userid, uname, phone_num, car_plate)
VALUES (576, 'alvin', '81005199', 'sgu1256t'), (877, 'dominic', '97972841', 'sga8814e'), (112, 'desmond', '97551488', 'slj8422y');

CREATE TABLE carpark
(carparkid INT (10), location VARCHAR(35) NOT NULL,
PRIMARY KEY (carparkid));

INSERT INTO carpark (carparkid, location)
VALUES ('001', '25 toa payoh lorong 8'), ('002', '45 burghley drive'), ('003', 'ang mo kio hub');

CREATE TABLE lot
(carparkid INT(10) NOT NULL, lot_num INT(3) NOT NULL, lot_status ENUM('empty', 'reserved', 'occupied') DEFAULT 'empty');

INSERT INTO lot (carparkid, lot_num)
VALUES(001, 001), (001, 002), (001, 003), (001, 004), (001, 005), (002, 001), (002, 002), (002, 003), (002, 004), (002, 005), (003, 001), (003, 002), (003, 003), (003, 004), (003, 005);

Here are mine codes so far, but i need to alter carparkid in table lot foreign key to carpark. 到目前为止,这是我的地雷代码,但我需要更改表外键中的carparkid。 When i use this code: 当我使用此代码时:

ALTER TABLE lot
ADD CONSTRAINT FK_carparklot
FOREIGN KEY (carparkid) REFERENCES carpark(carparkid)

it works fine, but when i use this: 它工作正常,但是当我使用这个时:

ALTER TABLE lot
ADD CONSTRAINT FK_carparklot
FOREIGN KEY (carparkid) REFERENCES carpark(carparkid)
ON DELETE CASCADE            
ON UPDATE SET DEFAULT;

it gives me the error: 它给了我错误:

ERROR 1005 (HY000): Can't create table `carparkful`.`#sql-3b64_3` (errno: 150 "Foreign key constraint is incorrectly formed")

Operating as designed/documented for InnoDB and NDB engines. 按照InnoDB和NDB引擎的设计/文档进行操作。

According to DOCS : SET DEFAULT: This action is recognized by the MySQL parser, but both InnoDB and NDB reject table definitions containing ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT clauses 根据DOCS的说法:SET DEFAULT:MySQL解析器可以识别此操作,但是InnoDB和NDB都拒绝包含 ON DELETE SET DEFAULTON UPDATE SET DEFAULT子句的表定义

This implies On Update set default option/parameter is not supported 这表示在更新时不支持set default选项/参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE[HY000]: 一般错误: 1005 Can't create table `test`.`members` (errno: 150 “Foreign key constraint is misformed”) - SQLSTATE[HY000]: General error: 1005 Can't create table `test`.`members` (errno: 150 “Foreign key constraint is incorrectly formed”) SQLSTATE[HY000]: 一般错误: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is wrongly forms") - SQLSTATE[HY000]: General error: 1005 Can't create table `school`.`posts` (errno: 150 "Foreign key constraint is incorrectly formed") SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 - SQLSTATE[HY000]: General error: 1005 Can't create table `business`.`users` (errno: 150 "Foreign key constraint is incorrectly formed") Laravel 7 外键错误 - 错误 1005 (HY000) … 无法创建表 … `stored_on` (errno: 150) - Foreign Key Error - ERROR 1005 (HY000) … Can't create table … `stored_on` (errno: 150) 外键问题:错误1005(HY000):无法创建表(错误号:150) - Foreign key issue:ERROR 1005 (HY000): Can't create table (errno: 150) Laravel 5.4:SQLSTATE[HY000]:一般错误:1005 无法创建表“外键约束格式不正确” - Laravel 5.4: SQLSTATE[HY000]: General error: 1005 Can't create table "Foreign key constraint is incorrectly formed" 错误#1005-无法创建表`testdb`.`blog`(错误号:150“外键约束格式不正确”)? - error #1005 - Can't create table `testdb`.`blog` (errno: 150 “Foreign key constraint is incorrectly formed”)? 一般错误:1005 无法创建表...(errno:150“外键约束格式不正确” - General error : 1005 Can't create table ... (errno:150 "Foreign key constraint is incorrectly formed" 一般错误:1005 无法创建表(错误号:150“外键约束格式不正确”) - General error: 1005 Can't create table (errno: 150 "Foreign key constraint is incorrectly formed") : 1005 无法创建表 `shop`.`role_user` (errno: 150 “外键约束格式不正确”)") - : 1005 Can't create table `shop`.`role_user` (errno: 150 “Foreign key constraint is incorrectly formed”)")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM