簡體   English   中英

添加遷移不適用於 MySQL

[英]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,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 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 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM