1

I am having an issue, where .NETCore isn't dedicating my primary keys on scaffolding. I am getting this error "Could not scaffold the foreign key 'Parent2(SKU2,ID2)'. A key for 'SKU,ID' was not found in the principal entity type 'Parent'."

Here is the code to create my table

CREATE TABLE `Parent` (
`OBJ` int,
`SKU` varchar(255),
`ID` int,
PRIMARY KEY (`OBJ`),
KEY `FK` (`SKU`, `ID`)
);

CREATE TABLE `Child` (
`IDC` int,
`SKU` varchar(255),
`ID` int,
 PRIMARY KEY (`IDC`),
 KEY `FK` (`SKU`, `ID`)
);

All I want to do is link the child to parent using the SKU, so if the SKU changes, it will change on the child too.

C.Ikongo
  • 1,706
  • 1
  • 16
  • 15
  • 1
    you should read up on foreign keys https://www.w3schools.com/sql/sql_foreignkey.asp – nbk Nov 18 '19 at 01:33
  • @nbk Apparently I can't create composite keys in EF https://stackoverflow.com/questions/53842449/mysql-with-entityframework-core-composite-foreign-key – C.Ikongo Nov 18 '19 at 01:56
  • I think you can, most is for sqlserver, but it proves it is possible. So you should give a try. https://stackoverflow.com/questions/19792295/mapping-composite-keys-using-ef-code-first – nbk Nov 18 '19 at 02:21

0 Answers0