不止一个迁移配置类型被发现在程序集“SMSApp”。指定要使用的一个名字 [英] More than one migrations configuration type was found in the assembly 'SMSApp'. Specify the name of the one to use

查看:1070
本文介绍了不止一个迁移配置类型被发现在程序集“SMSApp”。指定要使用的一个名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用code第一种方法开发一个MVC 5应用程序。

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

我面临的一个问题。在第一次当我尝试下面的命令对应的,它的工作和生成表在该数据库中。但是当我改变了一些更多的类,然后试图与第2的查询,它工作在这种情况下,但是当我试图在第三个命令,它给了这条消息给我。

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.

=============================第一步================ =====================================

=============================First Step=====================================================

启用-迁移-ContextTypeName IdentityDb -MigrationsDirectory DAL \ IdentityMigrations

enable-migrations -ContextTypeName IdentityDb -MigrationsDirectory DAL\IdentityMigrations

启用-迁移-ContextTypeName SMSContext -MigrationsDirectory DAL \ SMSMigrations

enable-migrations -ContextTypeName SMSContext -MigrationsDirectory DAL\SMSMigrations

==========================第二步=================== ====================================

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

添加迁移-ConfigurationTypeName SMSApp.DAL.IdentityMigrations.ConfigurationInitialCreate

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

添加迁移-ConfigurationTypeName SMSApp.DAL.SMSMigrations.ConfigurationInitialCreate

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

=========================第三步==================== =====================================

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

更新数据库-ConfigurationTypeName SMSApp.DAL.IdentityMigrations.Configuration -verbose

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

更新数据库-ConfigurationTypeName SMSApp.DAL.SMSMigrations.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.

在我执行下面的命令,它给了下面的异常。

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

更新 - 数据库-TargetMigration $ InitialDatabase -verbose

Update-Database -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?

推荐答案

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

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

Update-Database -ConfigurationTypeName MyRenamedConfiguration

这篇关于不止一个迁移配置类型被发现在程序集“SMSApp”。指定要使用的一个名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆