gpt4 book ai didi

MySQL Workbench - 正向工程 - 错误 1005 : Can't create table (errno: 150)

转载 作者:行者123 更新时间:2023-11-29 03:06:02 25 4
gpt4 key购买 nike

我在 MacOSX 上使用 MySQL Workbench 5.2.45 我使用 EER 图功能设计了一个数据库,然后尝试正向工程生成我的数据库以放置在我的本地服务器上。我收到错误代码:错误 1005:无法创建表(错误号:150)

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';

CREATE SCHEMA IF NOT EXISTS `Finance` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `Finance` ;

-- -----------------------------------------------------
-- Table `Finance`.`DatabaseUser`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Finance`.`DatabaseUser` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`FirstName` VARCHAR(255) NOT NULL ,
`LastName` VARCHAR(255) NOT NULL ,
`Tel` VARCHAR(255) NULL ,
`Email` VARCHAR(255) NOT NULL,
`Password` VARCHAR(255) NOT NULL ,
`Admin` CHAR(1) NOT NULL DEFAULT 'N' ,
`Project1` CHAR(1) NOT NULL DEFAULT 'N' ,
`Project2` CHAR(1) NOT NULL DEFAULT 'N' ,
`Project3` CHAR(1) NOT NULL DEFAULT 'N' ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `Finance`.`Entities`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Finance`.`Entities` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`CreatorID` INT(11) NOT NULL ,
`FullName` VARCHAR(255) NOT NULL ,
`ShortName` VARCHAR(255) NULL ,
PRIMARY KEY (`ID`) ,
INDEX `Creator_idx` (`CreatorID` ASC) ,
CONSTRAINT `CreatorEntities`
FOREIGN KEY (`CreatorID` )
REFERENCES `Finance`.`DatabaseUser` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `Finance`.`Grant`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `Finance`.`Grant` (
`ID` INT(11) NOT NULL AUTO_INCREMENT ,
`CreatorID` INT(11) NOT NULL ,
`DonorID` INT(11) NOT NULL ,
`RecipientID` INT(11) NOT NULL ,
`Name` VARCHAR(255) NOT NULL ,
`Year` YEAR NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `Creator_idx` (`CreatorID` ASC) ,
INDEX `index3` (`DonorID` ASC, `RecipientID` ASC) ,
CONSTRAINT `CreatorGrant`
FOREIGN KEY (`CreatorID` )
REFERENCES `Finance`.`DatabaseUser` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `InstrumentGrant`
FOREIGN KEY (`DonorID` , `RecipientID` )
REFERENCES `Finance`.`Entities` (`ID` , `ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

USE `Finance` ;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

我一直在尝试帖子 ( Error Code: 1005. Can't create table '...' (errno: 150)) 中建议的解决方案,但这似乎不是问题所在。1.数据类型相同2.我引用的是主键3.外键名称是唯一的4.表都是InnoDB5. 不涉及 SET NULL等

你能帮忙吗?

最佳答案

更改Grant 表中的外键约束。

引用http://www.sqlfiddle.com/#!2/04945

  CONSTRAINT `InstrumentGrant`
FOREIGN KEY (`RecipientID`)
REFERENCES `Entities` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `InstrumentGrant_2`
FOREIGN KEY (`DonorID`)
REFERENCES `Entities` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION

根据需要命名约束。

关于MySQL Workbench - 正向工程 - 错误 1005 : Can't create table (errno: 150),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15013153/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com