Alter a Column with migration file?

Using orchad 1.6 in the migration file I have just altered a table and added a column. I need this column to be NotNull, but it doesnt allow you to alter a table enter a NotNull type, so i've used Nullable and entered data into the existing columns.

I then want to edit this column and change it to a Nullable, but am unsure how....

public int UpdateFrom37()
        {
            SchemaBuilder.AlterTable("ManufacturedProductOrders", table => table
                .AddColumn<DateTime>("DateOrdered", c => c.Nullable())
                );

            return 38;
        }

        public int UpdateFrom38()
        {
            SchemaBuilder.AlterTable("ManufacturedProductOrders", table => table
                .AlterColumn("DateOrdered", c => c.WithType(dbType.???????????
                );
        }

I guess you want to change from NULL to NOT NULL, right? The code above clearly states that you already have a nullable column.

AlterColumn command does not currently allow changing column 'nullability'.

Your best option is to issue a manual ALTER TABLE command through SchemaBuilder.ExecuteSql() or directly in the database. You can read about it eg. here.

链接地址: http://www.djcxy.com/p/76282.html

上一篇: 如何限制主键列中的空白值

下一篇: 使用迁移文件更改列?