问题
I have two tables Project
and ProjectMedia
. they are defined as follow:
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;
ID
and LANG
are a composite primary key in the Project
table.
ProjectMedia
table definition:
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;
I have added two columns into ProjectMedia PROJECT_ID
and LANG
and I have created a composite foreign key for them to reference them into project
table
but when I execute scaffold command as follow: I am getting this message
dotnet ef dbcontext scaffold "server=localhost;database=mydb;user=root;" "MySql.Data.EntityFrameworkCore" --output-dir "Persistence" --context "MyDbContext" --force
Could not scaffold the foreign key 'mydb.project_media(PROJECT_ID)'. A key for 'ID' was not found in the principal entity type 'Project'. Could not scaffold the foreign key 'mydb.project_media(LANG)'. A key for 'LANG' was not found in the principal entity type 'Project'.
What should I do?
来源:https://stackoverflow.com/questions/53842449/mysql-with-entityframework-core-composite-foreign-key