gpt4 book ai didi

c# - Entity Framework 代码优先 + mysql System.NullReferenceException 第一次迁移

转载 作者:行者123 更新时间:2023-11-29 01:07:40 25 4
gpt4 key购买 nike

我正在尝试使用 MySQL 数据库(ef 代码优先方法,VS 2013 专业版)。我关注these instructions .

我的问题是启用迁移后我无法进行第一次迁移。我使用命令 Add-migration migrationName 时出现错误:

"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 MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection connection) ...

Object reference not set to an instance of an object.".

我试图解决它 f.e.在 this方式。但是现在我发现this :

"This can be caused by not specifying a required parameter for a scenario that you are using. For example specifying a connection string without specifying the provider name."

所以问题可能出在我的连接字符串中。

我有来自 VS > Server Explorer 的连接字符串,存在到我的数据库的“事件”连接。我查看了连接属性并将连接字符串复制到我的 web.config 中。

在我的项目中引用了 MySql.Data、MySql.Data.Entity.EF6 和 MySql.Web。

有人知道我该怎么做吗?

最佳答案

我之前至少来过两次新设置的 EF+MySQL 项目,在尝试启用代码优先迁移时,这给了我与 OP 完全相同的错误和堆栈跟踪。两次我都花了很长时间才找到最终有效的解决方案。

请确保您的 DbContext 类具有以下属性:

[DbConfigurationType(typeof(MySqlEFConfiguration))]
class MyDbContext : DbContext
{
// ...
}

关于c# - Entity Framework 代码优先 + mysql System.NullReferenceException 第一次迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34426445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com