Orchardcms 使用迁移文件更改列?
在迁移文件中使用orchad 1.6,我刚刚修改了一个表并添加了一列。我需要此列为NotNull,但它不允许您更改表并输入NotNull类型,因此我使用了Nullable并将数据输入到现有列中 然后我想编辑此列并将其更改为可空,但不确定如何Orchardcms 使用迁移文件更改列?,orchardcms,orchardcms-1.6,orchardcms-1.7,Orchardcms,Orchardcms 1.6,Orchardcms 1.7,在迁移文件中使用orchad 1.6,我刚刚修改了一个表并添加了一列。我需要此列为NotNull,但它不允许您更改表并输入NotNull类型,因此我使用了Nullable并将数据输入到现有列中 然后我想编辑此列并将其更改为可空,但不确定如何 public int UpdateFrom37() { SchemaBuilder.AlterTable("ManufacturedProductOrders", table => table
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.???????????
);
}
public int UpdateFrom37()
{
AlterTable(“ManufacturedProductOrders”,table=>table
.AddColumn(“DateOrdered”,c=>c.Nullable())
);
返回38;
}
public int UpdateFrom38()
{
AlterTable(“ManufacturedProductOrders”,table=>table
.AlterColumn(“DateOrdered”,c=>c.WithType(dbType.)。???????????
);
}
我猜您希望从NULL更改为notnull,对吗?上面的代码清楚地表明您已经有了一个可为NULL的列
AlterColumn
命令当前不允许更改列的“可空性”
您最好的选择是通过SchemaBuilder.ExecuteSql()或直接在数据库中发出手动
ALTER TABLE
命令。您可以阅读相关内容,例如..是否需要使用ExecuteSql()?有一个AlterTable()方法,为什么这不是推荐的解决方案?我对Orchard不是很有经验,所以我不太明白。谢谢!