添加迁移不适用于MySQL [英] Add-Migration not working with MySQL

查看:148
本文介绍了添加迁移不适用于MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 https://aspnetboilerplate.com/Templates .我正在使用MySQL,并按照链接 https://aspnetboilerplate.com/中提到的步骤进行操作页面/文档/EF-MySql-Integration .但是当我运行Add-Migration命令时,它给出了错误.

I have downloaded Asp.Net MVC 5.x Single page web application from https://aspnetboilerplate.com/Templates. I'm using MySQL and followed the steps mentioned in link https://aspnetboilerplate.com/Pages/Documents/EF-MySql-Integration. But when I run the Add-Migration command it gives the error.

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 \ Migrations \ Configuration.cs

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

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

错误:

PM> Add-Migration"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连接) System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<> c__DisplayClass1.b__0(Tuple 3 k) at System.Collections.Concurrent.ConcurrentDictionary 2.GetOrAdd(TKey 键,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输入)位于 System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
在System.Data.Entity.Internal.InternalContext.Initialize()在 System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() 在 System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() 在Abp.EntityFramework.AbpDbContext.RegisterToChanges()在 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解析器)位于 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置,DbContext usersContext,DatabaseExistenceState existState,布尔值,称为ByCreateDatabase,位于 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置) System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration),位于 System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() 在System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()处 你调用的对象是空的. PM>

PM> Add-Migration "AbpZero_Initial" System.NullReferenceException: Object reference not set to an instance of an object. at MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection connection) at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.b__0(Tuple3 k) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 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.RetryLazy2.GetValue(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize() at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes() at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext() at Abp.EntityFramework.AbpDbContext.RegisterToChanges() at Abp.Zero.EntityFramework.AbpZeroDbContext3..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, Func1 resolver) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext, DatabaseExistenceState existenceState, Boolean calledByCreateDatabase) at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration migrationsConfiguration) at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() Object reference not set to an instance of an object. PM>

推荐答案

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

MySql.Data version 6.9.11 is working well. Higher versions have problems. So, Try to use nuget.org/packages/MySql.Data/6.9.11. Or if you are using EF Core, you can use Npgsql.EntityFrameworkCore.PostgreSQL

这篇关于添加迁移不适用于MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆