使用迁移文件更改列?

Joh*_*ohn 5 orchardcms orchardcms-1.6 orchardcms-1.7

在迁移文件中使用orchad 1.6我刚刚更改了一个表并添加了一列.我需要此列为NotNull,但它不允许您更改表输入NotNull类型,因此我使用了Nullable并将数据输入到现有列中.

然后,我想编辑此列并将其更改为Nullable,但我不确定如何....

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.???????????
                );
        }
Run Code Online (Sandbox Code Playgroud)

Pio*_*myd 5

我想你想要从NULL更改为NOT NULL,对吧?上面的代码清楚地表明您已经有一个可以为空的列.

AlterColumn 命令当前不允许更改列'nullability'.

您最好的选择是ALTER TABLE通过SchemaBuilder.ExecuteSql()或直接在数据库中发出手动命令.你可以阅读它,例如.在这里.