[英]Add-Migration not working with MySQL
我已经从https://as.netboilerplate.com/Templates下载了 Asp.Net MVC 5.x 单页 web 应用程序。 我正在使用 MySQL 并按照链接https://as.netboilerplate.com/Pages/Documents/EF-MySql-Integration中提到的步骤进行操作。 但是当我运行Add-Migration
命令时,它给出了错误。
我的公司.我的项目.Web\Web.Config:
<add name="Default" connectionString="Server=127.0.0.1;port=3306;Database=SparTestDb;uid=root;password=root" providerName="MySql.Data.MySqlClient"/>
我的公司.MyProject.EntityFramework\Migrations\Configuration.cs
public Configuration()
{
AutomaticMigrationsEnabled = false;
ContextKey = "Spar";
SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
}
错误:
PM> 添加迁移“AbpZero_Initial”System.NullReferenceException:Object 引用未设置为 object 的实例。在 MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection 连接)在 System.Data.CobreProviderD.Commonity。 System.Data.Entity.Utilities.DbProviderServicesExtensions 处的 GetProviderManifestToken(DbConnection 连接)。System.Data.Entity.Infrastructure.DefaultManifestTokenResolver 处的 GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection 连接)。<>c__DisplayClass1.b__0(元组
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 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.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, Func
System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration配置,DbContext usersContext,DatabaseExistenceState existenceState,Boolean calledByCreateDatabase)在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() Object 参考不设置为 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;"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.