zoukankan      html  css  js  c++  java
  • code first 数据迁移:新增字段出现 不能将值 NULL 插入列 'ProductAttribute',表 'dbo.StoreProduct';列不允许有空值。UPDATE 失败。

    使用code first 做数据迁移新增非空字段,提示如下错误: 

    AlterColumn("dbo.StoreProduct", "StoreProductAttribute", c => c.String(nullable: false, maxLength: 20, defaultValue: "固定资产"));

    不能将值 NULL 插入列 'ProductAttribute',表 'dbo.StoreProduct';列不允许有空值。UPDATE 失败。

    语句已终止。

    由于数据表StoreProduct中ProductAttribute值有部分为NULL,做迁移就会出现这样的错误。

    解决办法是在修改字段属性前,先赋值 给 ProductAttribute 字段。

    public override void Up()
            {
                Sql("update StoreProduct set StoreProductAttribute='固定资产'");
    
                AlterColumn("dbo.StoreProduct", "StoreProductAttribute", c => c.String(nullable: false, maxLength: 20, defaultValue: "固定资产"));
            }
  • 相关阅读:
    checkbox radio select 选中总结
    vue-cli3总结
    数组总结
    Object 总结
    ajax总结
    canvas
    移动端事件
    微服务架构 SpringBoot(一)
    spring+activemq实战之配置监听多队列实现不同队列消息消费
    Integer 数值比较
  • 原文地址:https://www.cnblogs.com/chear/p/2890020.html
Copyright © 2011-2022 走看看