具有EntityFramework核心的MySQL-复合外键

时间:2018-12-18 23:11:27

标签: c# mysql .net-core entity-framework-core

我有两个表ProjectProjectMedia。它们的定义如下:

CREATE TABLE `project` (
  `ID` int(11) NOT NULL,
  `LANG` char(2) NOT NULL,
  `NAME` varchar(64) CHARACTER SET utf8 DEFAULT NULL,
  `DESCS` varchar(2048) CHARACTER SET utf8 DEFAULT NULL,
  `SHORT_DESC` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
  PRIMARY KEY (`ID`,`LANG`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

IDLANGProject表中的复合主键。

ProjectMedia表定义:

CREATE TABLE `project_media` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `PATH` varchar(1024) DEFAULT NULL,
  `TYPE` char(1) DEFAULT NULL,
  `IS_LOCAL_FILE` bit(1) DEFAULT NULL,
  `PROJECT_ID` int(11) NOT NULL,
  `LANG` char(2) NOT NULL,
  PRIMARY KEY (`ID`),
  KEY `PROJECT_MEDIA_PROJECT_PROJECT_ID_LANG_idx` (`PROJECT_ID`,`LANG`),
  CONSTRAINT `PROJECT_MEDIA_PROJECT_PROJECT_ID_LANG` FOREIGN KEY (`PROJECT_ID`, `LANG`) REFERENCES `project` (`ID`, `LANG`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

我在ProjectMedia PROJECT_IDLANG中添加了两列,并创建了一个复合外键供它们将其引用到project表中

但是当我按如下方式执行脚手架命令时:我收到此消息

dotnet ef dbcontext scaffold "server=localhost;database=mydb;user=root;" "MySql.Data.EntityFrameworkCore" --output-dir "Persistence" --context "MyDbContext" --force
  

无法设置外键“ mydb.project_media(PROJECT_ID)”。一种   在主体实体类型“项目”中找不到“ ID”的键。   无法设置外键“ mydb.project_media(LANG)”。关键   在主要实体类型“项目”中找不到“ LANG”。

我该怎么办?

0 个答案:

没有答案