在程序集“SMSApp”中发现了不止一种迁移配置类型。指定要使用的名称

2024-05-09

我正在使用代码优先方法开发 mvc 5 应用程序。

我面临一个问题。第一次当我尝试下面的命令时,它起作用并在该数据库中生成表。但是当我更改了更多类,然后尝试前两个查询时,它在这种情况下有效,但是当我尝试第三个命令时,它给了我这条消息。



First step
==========

enable-migrations -ContextTypeName IdentityDb -MigrationsDirectory DAL\IdentityMigrations

enable-migrations -ContextTypeName SMSContext -MigrationsDirectory DAL\SMSMigrations

Second Step
===========

add-migration -ConfigurationTypeName SMSApp.DAL.IdentityMigrations.Configuration "InitialCreate"

add-migration -ConfigurationTypeName SMSApp.DAL.SMSMigrations.Configuration "InitialCreate"

Third Step
==========

update-database -ConfigurationTypeName SMSApp.DAL.IdentityMigrations.Configuration -verbose

update-database -ConfigurationTypeName SMSApp.DAL.SMSMigrations.Configuration -verbose

  

看到第一个错误:

PM> add-migration -ConfigurationTypeName SMSApp.DAL.IdentityMigrations.Configuration "InitialCreate"
Scaffolding migration ' '.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration InitialCreate' again.

A previous migration called 'InitialCreate' was already applied to the target database. If you meant to re-scaffold 'InitialCreate', revert it by running 'Update-Database -TargetMigration $InitialDatabase', then delete '201409261933262_InitialCreate1.cs' and run 'Add-Migration InitialCreate' again.

之后我执行了以下命令,它给出了以下异常。

更新数据库 -TargetMigration $InitialDatabase -verbose

PM> Update-Database -TargetMigration $InitialDatabase -verbose
Using StartUp project 'SMSApp'.
Using NuGet project 'SMSApp'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.Data.Entity.Migrations.Infrastructure.MigrationsException: More than one migrations configuration type was found in the assembly 'SMSApp'. Specify the name of the one to use.
   at System.Data.Entity.Utilities.TypeFinder.FindType(Type baseType, String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
   at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration(Type contextType, String configurationTypeName, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
More than one migrations configuration type was found in the assembly 'SMSApp'. Specify the name of the one to use.

现在我很担心如何解决?


您需要指定更新数据库时要使用的配置。

Update-Database -ConfigurationTypeName MyRenamedConfiguration
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在程序集“SMSApp”中发现了不止一种迁移配置类型。指定要使用的名称 的相关文章

  • 无法转换类型为“NHibernate.Collection.Generic.PersistentGenericBag”的对象

    public List
  • .net 中的计时器合并

    Windows 7 引入了计时器合并 提高了能源效率 哪些托管 API 公开了计时器容差 似乎利用此功能的唯一方法是 p invoke设置等待定时器 http msdn microsoft com en us library windows
  • EditorFor 的最小值和最大值

    我一直在尝试这段代码来设置我的最小值和最大值EditorFor
  • 如何在.NET Core上直接调用F#编译器?

    UPD 我想直接从 NET Core SDK 调用 F 编译器 即 fsc 我了解 dotnet build co 但当我只需要编译一个简单的问题时 即 fsc file fs 就足够的情况下 我不想涉及它们 我尝试在 NET Core S
  • 如何在种子实体框架版本 6.x 中通过 AddOrUpdate 方法插入身份[重复]

    这个问题在这里已经有答案了 我有一个具有身份列的实体 作为数据种子的一部分 我想对系统中的 标准数据 使用特定的标识符值 我不想禁用身份 只有我想在迁移种子中设置 IDENTITY INSERT ON 我的代码是 protected ove
  • 在 SpecFlow 测试中使用 ChromeDriver

    因此 正如我们所知 当您使用 SpecFlow 时 如果您重复使用另一个测试中的步骤 它会自动将其拉入并重复使用 但是 我遇到了一个问题 测试 A 登录我 测试 B 登录并确认主页是正确 但当我开始使用测试 B 时 测试 A 正在初始化 C
  • MVC 3 EF 4.1 dbContext - 删除具有不可空外键关系的一对多数据对象

    我正在使用 MVC 3 EF 4 1 和 dbContext 我需要知道如何删除具有不可空外键的一对多关系的实体 当我删除子实体并执行 SaveChanges 时 出现错误 操作失败 无法更改关系 因为一个或多个外键属性不可为空 当关系发生
  • 使对象在运行时不可变 [C#]

    有什么方法 我希望利用反射 可以使实例化对象不可变及其所有公共财产 我有一个来自其他人的代码库 没有可用源 的类 我需要使用它 并且我基本上希望在实例化该类后 如果任何地方的任何代码段尝试调用该类中的公共设置器 则抛出异常 注意 我不想在类
  • WPF Window 类的 IDisposable 成员

    当我将 IDisposable 类成员添加到 Windows 窗体 Form 类时 我将处置代码添加到 Form 的 Dispose 方法中 当我将 IDisposable 类成员添加到 WPF Window 类 不是 IDisposabl
  • 在 C++/CLI 中实现 IEnumerable

    我在实施时遇到问题IEnumerable
  • 从 GUID 获取类型

    由于种种原因 我需要在C 中实现类型缓存机制 幸运的是 CLR 提供了Type GUID来唯一标识一个类型 不幸的是 我找不到任何方法来根据此 GUID 查找类型 有Type GetTypeFromCLSID 但根据我对文档 和实验 的理解
  • 公共交通错误队列正在消耗,但仍然不为空

    我正在使用 Mastransit 3 5 0 和 RabbitMq 如果队列消费者抛出异常 则默认由 MoveExceptionToTransportFilter 处理异常并移至 error 队列 对于 error 队列 我有单独的消费者
  • 为什么必须在 C# 中 Close() 文件?

    我知道这可能看起来很愚蠢 但为什么以下代码仅在我 Close 文件时才有效 如果我不关闭文件 则不会写入整个流 Steps 在表单加载时运行此代码 显示后使用鼠标关闭表单 程序终止 当文件对象超出范围时 不应该自动刷新或关闭吗 我是 C 新
  • 为什么 F# 的默认集合是排序的,而 C# 的不是?

    当从 C 世界迁移到 F 最惯用的可能 思维方式时 我发现了这个有趣的差异 在 C 的 OOP mutable 世界中 默认的集合集合似乎是HashSet https learn microsoft com en us dotnet api
  • 单元测试验证失败

    我正在运行我的单元测试PostMyModel路线 然而 在PostMyModel 我用的是线Validate
  • 运行需要 MySql.Data 的内置 .NET 应用程序

    我在运行我编写的内置 NET 应用程序时遇到问题 我的应用程序使用最新的 MySql 连接器 该连接器安装在我的系统上 当我尝试将其添加为引用时 该连接器显示为 NET 4 Framwork 组件 当我在环境中以调试模式运行应用程序时 一切
  • 如何在 Asp.NET MVC 中使用 RedirectToAction() 传递多个对象?

    我想使用redirectToAction 方法传递多个对象 下面是我重定向到的操作结果 public ActionResult GetEmployees Models Department department Models Categor
  • 编译器失败,错误代码-1073741819

    我们遇到以下错误 而且每次都需要重启服务器 The compiler failed with error code 1073741819 此外 ASP Net 工作正常 只有 ASP Net MVC 应用程序无法工作 任何想法 我的错误代码
  • 在 asp.net MVC 中使用活动目录进行身份验证

    我想使用活动目录对我的 asp net mvc 项目中的用户进行身份验证 在网上冲浪了几个小时后 我没有找到任何对我有用的东西 我已经看到了所有结果 但什么也没有 我尝试按照许多帖子的建议编辑我的 web config 如果有人可以帮助我提
  • INotifyPropertyChanged 和 propertyName

    我一直不确定它的含义propertyName实施时INotifyPropertyChanged 所以一般来说你实现INotifyPropertyChanged as public class Data INotifyPropertyChan

随机推荐