zoukankan      html  css  js  c++  java
  • EntityFramework 数据库的迁移

    第一步:在程序包管理器控制台里: Enable-Migrations -ProjectName EF所在的项目名称

    第二步:运行后会在字段生成Migrations文件夹,Migrations->Configuration.cs 类里把AutomaticMigrationsEnabled改为true(即设为model有改动自动更新数据库)

    这里可以直接用命令更新数据库

     internal sealed class Configuration : DbMigrationsConfiguration<FoundationDataTool.Models.DB>
        {
            public Configuration()
            {
                AutomaticMigrationsEnabled = true;
                AutomaticMigrationDataLossAllowed = true;
            }
    
            protected override void Seed(FoundationDataTool.Models.DB context)
            {
                //  This method will be called after migrating to the latest version.
    
                //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
                //  to avoid creating duplicate seed data. E.g.
                //
                //    context.People.AddOrUpdate(
                //      p => p.FullName,
                //      new Person { FullName = "Andrew Peters" },
                //      new Person { FullName = "Brice Lambson" },
                //      new Person { FullName = "Rowan Miller" }
                //    );
                //
            }
        }

    然后执行Update-DataBase -ProjectName VerifySystem.Domain  (dbcontext的文件)

    如果数据实体的属性改变 使用如下命令进行数据库的迁移:

      Add-Migration updateuser

      Update-DataBase -ProjectName MedicalInsurance.Domain 

    使用ef  连接mysql的时候需要注意的问题:

    1.使用命令来创建数据库,

        Enable-Migrations -ProjectName MedicalInsurance.Domain(此生生migration文件修改如上)    

        Update-DataBase -ProjectName MedicalInsurance.Domain 

    2.使用命令来迁移数据库,

       Add-Migration updateuser

      Update-DataBase -ProjectName MedicalInsurance.Domain 

     其中在执行add命令的时候出现错误:No MigrationSqlGenerator found for provider 'MySql.Data.MySqlClient'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.

    参考在http://stackoverflow.com/questions/15142841/no-entity-framework-provider-found-for-mysql-data-mysqlclient-ado-net-provider找到了答应,需要在Context指定mySql的配置文件

    在context文件上加一个注解

      [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]

  • 相关阅读:
    jmeter和ab的对比
    jmeter
    (原)InsightFace及其mxnet代码
    (原)CosFace/AM-Softmax及其mxnet代码
    (原)SphereFace及其pytorch代码
    (原)模型的参数初始化
    (原)python中不同文件之间使用所谓的全局变量
    (原+译)pytorch中保存和载入模型
    (原)torch模型转pytorch模型
    (原+译)使用numpy.savez保存字典后读取的问题
  • 原文地址:https://www.cnblogs.com/nele/p/5275254.html
Copyright © 2011-2022 走看看