【问题标题】:Alter a Column with migration file?使用迁移文件更改列?
【发布时间】:2013-09-19 11:47:11
【问题描述】:

在迁移文件中使用 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.???????????
                );
        }

【问题讨论】:

    标签: orchardcms orchardcms-1.6 orchardcms-1.7


    【解决方案1】:

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

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

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

    【讨论】:

    • 有必要使用 ExecuteSql() 吗?有一个 AlterTable() 方法,为什么不应该是推荐的解决方案?我对Orchard不是很有经验,所以我不太了解。谢谢!
    猜你喜欢
    • 2021-06-23
    • 2015-02-07
    • 2015-12-18
    • 2011-02-17
    • 1970-01-01
    • 2013-01-28
    • 2017-07-28
    • 1970-01-01
    相关资源
    最近更新 更多