How do I set a default value for a new column using EF6 migrations?

倾然丶 夕夏残阳落幕 提交于 2020-02-06 04:42:42

问题


I know that you can manually manipulate the EF generated migration file to add in the 'defaultValue: 1' parameter to the 'AddColumn' method, but it does not seem to be generating the correct Oracle translation when I look at the generated script.

See my EF migration 'Up' method below:

public override void Up()
    {
        AddColumn("TABLE", "NEW_COLUMN", c => c.Decimal(nullable: false, precision: 10, scale: 0, defaultValue: 1));
    }

And after running 'update-database -script' I get the following corresponding SQL line:

alter table "TABLE" add ("NEW_COLUMN" number(10, 0) not null)

Running this against the database will not set the default value of the existing rows to the desired value of 1... What am I missing here?

I am using EF version 6.0.0.0 and Oracle Managed Data Access version 6.121.2.0

来源:https://stackoverflow.com/questions/36068914/how-do-i-set-a-default-value-for-a-new-column-using-ef6-migrations

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