简体   繁体   English

使列不可为空,EF外键错误

[英]Made column Not Nullable, EF foreign keys errors

I changed a column in a table from NULL to NOT NULL, updated model from database, and am now presented with the following error: 我将表中的列从NULL更改为NOT NULL,从数据库更新了模型,现在出现以下错误:

Error 3 Running transformation: Multiplicity conflicts with the referential constraint in Role 'registration' in relationship 'fk_cost_centre_registration'. 错误3运行转换:多重性与关系'fk_cost_centre_registration'中的角色'registration'中的引用约束冲突。 Because all of the properties in the Dependent Role are non-nullable, multiplicity of the Principal Role must be '1'. 因为从属角色中的所有属性都是不可为空的,所以主体角色的多重性必须为'1'。

I am unsure how to fix this. 我不确定如何解决此问题。 What have I done wrong? 我做错了什么?

I have made many changes to a lot of the navigation properties on one of the tables I have modified, and can't delete it and re-add it, or else I need to rename all the navigation properties and remove a lot that I don't need, with possible regression issues. 我对一个已修改的表上的许多导航属性进行了许多更改,无法删除并重新添加,否则我需要重命名所有导航属性并删除很多我不知道的不需要,可能存在回归问题。 This is another issue I am facing with EF - as I have changed some navigation properties, removing and readding a table is a massive issue. 这是EF面临的另一个问题-由于我更改了一些导航属性,因此删除和读取表是一个大问题。 Yes, I can document the properties I need, but - maybe I am doing something wrong? 是的,我可以记录所需的属性,但是-也许我做错了什么?

Simply change multiplicity via properties tab. 只需通过属性选项卡更改多重性。 If Dependent Role is nullable its multiplicity will be 0..1 (Zero or One of ...) . 如果从属角色为空,则其多重性将为0..1 (Zero or One of ...) If it is not nullable it should be 1 (One of ...) . 如果它不能为空,则应为1 (One of ...) So open your model, find you foreign key and change appropriate multiplicity as shown in the pictures 因此,打开模型,找到外键并更改适当的多重性,如图所示

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM