添加迁移不适用于MySQL

时间:2018-05-02 10:08:12

标签: c# entity-framework asp.net-mvc-5 aspnetboilerplate asp.net-boilerplate

我从https://aspnetboilerplate.com/Templates下载了Asp.Net MVC 5.x单页面Web应用程序。我正在使用MySQL并按照链接https://aspnetboilerplate.com/Pages/Documents/EF-MySql-Integration中提到的步骤进行操作。但是当我运行Add-Migration命令时,它会给出错误。

MyCompany.MyProject.Web \ Web.Config中:

<add name="Default" connectionString="Server=127.0.0.1;port=3306;Database=SparTestDb;uid=root;password=root" providerName="MySql.Data.MySqlClient"/>

MyCompany.MyProject.EntityFramework \迁移\ Configuration.cs

public Configuration()
{
    AutomaticMigrationsEnabled = false;
    ContextKey = "Spar";

    SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}

错误:

  

PM&GT;添加迁移“AbpZero_Initial”System.NullReferenceException:   你调用的对象是空的。在   MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(的DbConnection   连接)   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(的DbConnection   连接)   System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices   providerServices,DbConnection连接)at   System.Data.Entity.Infrastructure.DefaultManifestTokenResolver&LT;&GT; c__DisplayClass1.b__0(元组3 k) at System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKEY的   key,Func 2 valueFactory) at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy 2.GetValue(TInput input)at   System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
  在System.Data.Entity.Internal.InternalContext.Initialize()at   System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()   在   System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()   at Abp.EntityFramework.AbpDbContext.RegisterToChanges()at   Abp.Zero.EntityFramework.AbpZeroDbContext 3..ctor(String nameOrConnectionString) at MyCompany.MyProject.EntityFramework.SparDbContext..ctor() in C:\Users\MyName\Downloads\MyCompany.MyProject (1)\3.3.0\src\MyCompany.MyProject.EntityFramework\EntityFramework\SparDbContext.cs:line 19 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Data.Entity.Infrastructure.DbContextInfo.CreateInstance() at System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func 1个解析器)at at   System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration   配置,DbContext usersContext,DatabaseExistenceState   presenceState,布尔名为ByBreateDatabase)at   System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration   配置)   System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration   migrationsConfiguration)at   System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()   在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()   你调用的对象是空的。 PM&GT;

1 个答案:

答案 0 :(得分:0)

MySql.Data版本6.9.11运行良好。更高版本有问题。因此,尝试使用nuget.org/packages/MySql.Data/6.9.11。或者,如果您使用的是EF Core,则可以使用Npgsql.EntityFrameworkCore.PostgreSQL