问题描述
我正在尝试对我的数据库进行正向工程,该数据库有 7 个表,但其中一个向我发送了错误.我真的不知道从这里开始做什么,因为它的设置就像我的其他表格一样,所以我不确定是什么导致了错误,谷歌返回了大量不同的答案.专辑 SQL:pastebin.com/A3axVAA5
I'm trying to forward engineer my databae that has 7 tables but one is shooting me an error. I don't really know what to do from here because it is setup just like the rest of my tables so I'm unsure what is causing the error and google returns a multitude of varied answers. Album SQL: pastebin.com/A3axVAA5
Executing SQL script in server
ERROR: Error 1005: Can't create table 'cat10e.recording' (errno: 150)
CREATE TABLE IF NOT EXISTS `cat10e`.`recording` (
`rec_id` SMALLINT NOT NULL,
`album_id` INT NOT NULL,
`rec_duration` TIME NOT NULL,
`rec_genre` VARCHAR(45) NOT NULL,
`rec_cost` DECIMAL(4,2) NOT NULL,
`rec_title` VARCHAR(45) NOT NULL,
`rec_date` DATE NOT NULL,
`rec_note` VARCHAR(255) NULL,
PRIMARY KEY (`rec_id`, `album_id`),
INDEX `fk_recording_album1_idx` (`album_id` ASC),
CONSTRAINT `fk_recording_album1`
FOREIGN KEY (`album_id`)
REFERENCES `cat10e`.`album` (`album_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
SQL script execution finished: statements: 21 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
推荐答案
查看 album
表的 DDL,album_id
列定义为:
Looking at the DDL for the album
table it looks like the album_id
column is defined as:
`album_id` SMALLINT NOT NULL
而 recording
表中的 album_id
列定义为:
Whereas the album_id
column in the recording
table is defined as:
`album_id` INT NOT NULL
尝试将 recording
表中的 album_id
列更改为:
Try changing the album_id
column in the recording
table to this:
`album_id` SMALLINT NOT NULL
如果您想设置从 recording
.album_id
到 album
.album_id
!
They have to match if you want to set up a FK from recording
.album_id
to album
.album_id
!
这篇关于错误:错误 1005:无法创建表 'cat10e.recording'(错误号:150)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!