Code First can#39;t enable migrations(Code First 无法启用迁移)
问题描述
我正在尝试启用迁移,但它引发了异常:
I'm trying to enable migrations but it's throwing an exception:
正在检查上下文是否针对现有数据库...System.TypeInitializationException:System.Data.Entity.Migrations.DbMigrationsConfiguration`1"的类型初始化程序引发了异常.---> System.TypeInitializationException:System.Data.Entity.Internal.AppConfig"的类型初始化程序引发了异常.---> System.Configuration.ConfigurationErrorsException:配置系统初始化失败---> System.Configuration.ConfigurationErrorsException:必须在section"标签上指定name"属性.
Checking if the context targets an existing database... System.TypeInitializationException: The type initializer for 'System.Data.Entity.Migrations.DbMigrationsConfiguration`1' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: The 'name' attribute must be specified on the 'section' tag.
我假设 App.config 文件设置不正确(它是在我添加 EF 包时自动设置的).我所做的只是添加连接字符串:
I'm assuming that the App.config file is not correctly set up (it was automatically set up when I added EF package). All I did was add the connection string:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section Name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<connectionStrings>
<add Name="MyContext" connectionString="data source=MYSERVER;initial catalog=CodeFirstTest;user id=***;password=***;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
我使用的是 SQL Server 2008 R2.
I'm using SQL Server 2008 R2.
因为我确实有一个连接字符串,所以我认为我不需要默认连接工厂.我对么?(注意:即使没有这部分,我仍然会遇到同样的异常)
As I do have a connection string, I don't believe I need the defaultconnectionfactory. Am I correct? (Note: Even without this section I'm still getting the same exception)
我还缺少什么?
推荐答案
当我的 <connectionString/>
条目位于 Web.config 的顶部时,我遇到了同样的问题,紧接着<配置>
.然后我试着把它移到 </configuration>
之前,它成功了.
I had the same issue when my <connectionString />
entry is on top part of the Web.config, Right after <configuration>
. Then I tried moving it right before </configuration>
, and it worked.
这篇关于Code First 无法启用迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Code First 无法启用迁移
基础教程推荐
- 如何激活MC67中的红灯 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30