Dependencies error after changing data type in Entity Framework?

大城市里の小女人 提交于 2019-12-08 11:31:35

问题


I've changed 2 columns type by specifying the attribute

[Column(TypeName = "date")]

on the properties:

public DateTime LastModified { get; set; } = DateTime.Now; 
public DateTime OriginalCreated { get; set; } = DateTime.Now;

When I run the application (MVC) I get an error:

Additional information: The object 'DF__StoryMode__Origi__25869641' is dependent on column 'OriginalCreated'.

ALTER TABLE ALTER COLUMN OriginalCreated failed because one or more objects access this column.

I followed this answer and dropped the two constraints, but they have been recreated again.

I tried to use new database by changing the Initial Catalog in the web.config file and still getting the same error!

EDIT

Solution: I set the two properties to have default values, thus EF create Default constraints for them in the database, and that is why the constraints are recreating themselves every time I run the application, EF creates them. So I commented out that portion and updated the database with the new data type, and it works

来源:https://stackoverflow.com/questions/40267769/dependencies-error-after-changing-data-type-in-entity-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!