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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26067259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:48:37  来源:igfitidea点击:

More than one migrations configuration type was found in the assembly 'SMSApp'. Specify the name of the one to use

.netasp.net-mvcentity-frameworkef-code-first

提问by maifs

I am developing a mvc 5 application using code first approach.

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

i am facing an issue . at first time when i try below comands , it worked and generate the table in that database. but when i changed some more classes and then tried with first 2 queries , it worked in that case but when i tried the third command, it gave this message to me.

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

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

see the first error:

看到第一个错误:

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.

After that i executed the below command, it gave the below exception.

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

Update-Database -TargetMigration $InitialDatabase -verbose

更新数据库 -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.

NOw i am worry how to resolve it?

现在我很担心如何解决它?

回答by Amirhossein Yari

You need to specify which configuration you want to use when updating the databases.

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

Update-Database -ConfigurationTypeName MyRenamedConfiguration

回答by Anees

Enable

使能够

  • Migrations
  • ContextTypeName DropDownList_plus_Crud_project.User_Complete
  • MigrationsDirectory Migrations.Identity

    1. If First DBContext is added already in your project then you have to add the second DBContext.
    2. Go to Tool>Nuget-Package-Console.
    3. Enable-Migrations -ContextTypeName ProjectName.DBContextName -MigrationsDirectory NameofFile Which you want to create
    4. Successfully Created 2nd Migration in your project.
  • 迁移
  • ContextTypeName DropDownList_plus_Crud_project.User_Complete
  • MigrationsDirectory Migrations.Identity

    1. 如果您的项目中已经添加了第一个 DBContext,那么您必须添加第二个 DBContext。
    2. 转到工具> Nuget-Package-Console。
    3. Enable-Migrations -ContextTypeName ProjectName.DBContextName -MigrationsDirectory NameofFile 要创建的文件
    4. 在您的项目中成功创建了第二次迁移。

enter image description here

在此处输入图片说明