使用迁移文件更改列?

时间:2013-09-19 11:47:12

标签: 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.???????????
                );
        }

1 个答案:

答案 0 :(得分:5)

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

AlterColumn命令目前不允许更改列“可空性”。

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