添加迁移不适用于 MySQL
Add-Migration not working with MySQL
我已经从 https://aspnetboilerplate.com/Templates. I'm using MySQL and followed the steps mentioned in link https://aspnetboilerplate.com/Pages/Documents/EF-MySql-Integration 下载了 Asp.Net MVC 5.x 单页 Web 应用程序。但是当我 运行 Add-Migration
命令时它给出了错误。
MyCompany.MyProject.Web\Web.配置:
<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:
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.ConcurrentDictionary
2.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.RetryLazy
2.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.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 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 版本 8.0.26 和 MySql.Data.Entitiframework 8.0.26,在调试源代码后我发现对于本地迁移 EF 尝试使用 SSL 连接,所以在我的案例帮助使用连接字符串参数关闭 ssl:
SslMode=none
示例连接字符串:
"server=localhost;port=3306;user id=root;password=1q2w][=[;database=TmpMigrations;persistsecurityinfo=True;Allow User Variables=True;SslMode=none;"
我已经从 https://aspnetboilerplate.com/Templates. I'm using MySQL and followed the steps mentioned in link https://aspnetboilerplate.com/Pages/Documents/EF-MySql-Integration 下载了 Asp.Net MVC 5.x 单页 Web 应用程序。但是当我 运行 Add-Migration
命令时它给出了错误。
MyCompany.MyProject.Web\Web.配置:
<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: 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(Tuple
3 k) at System.Collections.Concurrent.ConcurrentDictionary
2.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.RetryLazy
2.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.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 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 版本 8.0.26 和 MySql.Data.Entitiframework 8.0.26,在调试源代码后我发现对于本地迁移 EF 尝试使用 SSL 连接,所以在我的案例帮助使用连接字符串参数关闭 ssl:
SslMode=none
示例连接字符串:
"server=localhost;port=3306;user id=root;password=1q2w][=[;database=TmpMigrations;persistsecurityinfo=True;Allow User Variables=True;SslMode=none;"