Mysql 6.7.7 + EntityFramework 5.0 Code First 不能 Update-Database 问题的解决

1、修改 Migrations/Configuration.cs 文件
 namespace DataModel.Migrations
{
using System;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq; internal sealed class Configuration : DbMigrationsConfiguration<DataModel.SpaceDataContext>
{
public Configuration()
{
12 AutomaticMigrationsEnabled = true;
13
14 AutomaticMigrationDataLossAllowed = true;
15
16 SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator()); // This will add our MySQLClient as SQL Generator
} protected override void Seed(DataModel.SpaceDataContext 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" }
// );
//
}
}
}
2、修改 App.config 文件 entityFramework 节点
   <entityFramework>
<defaultConnectionFactory type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
<contexts>
<context type="DataModel.SpaceDataContext,DataModel">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[DataModel.SpaceDataContext,DataModel], [DataModel.Migrations.Configuration,DataModel]], EntityFramework" />
</context>
</contexts>
</entityFramework>
3、完事!! 注意红色高亮处哦

  

上一篇:锋利的jQuery-3--.css()获取和设置元素的数字属性


下一篇:Scrapy-下载中间件