我已经启用了迁移:
enable-Migrations -ProjectName ProjectOne -ContextTypeName MyIdentity.Config.MyIdentityContext -MigrationsDirectory Identity\\Migrations
我指定了我的上下文,因为它位于一个独立的命名空间中,我指定了该目录,因为我希望将迁移放在另一个目录中。
启用此类迁移后,我在预期位置(Identity \ Migrations文件夹)中获取预期的配置文件(我删除了种子过程中的注释)
Friend NotInheritable Class Configuration
Inherits DbMigrationsConfiguration(Of MyIdentityDbContext)
Public Sub New()
AutomaticMigrationsEnabled = False
MigrationsDirectory = "Identity\\Migrations"
End Sub
Protected Overrides Sub Seed(context As MyIdentityDbContext)
End Sub
End Class
在此之后我创建了一个迁移:
add-migration Initial
但后来我收到一条错误,指出该文件已经存在:
Scaffolding migration 'Initial'.
System.Runtime.InteropServices.COMException (0x80040400): Unable to add '201506111233565_Initial.vb'. A file with that name already exists.
Server stack trace:
at EnvDTE.ProjectItems.AddFromFileCopy(String FilePath)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at EnvDTE.ProjectItems.AddFromFileCopy(String FilePath)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.AddFile(Project project, String path)
at System.Data.Entity.Migrations.Extensions.ProjectExtensions.AddFile(Project project, String path, String contents)
at System.Data.Entity.Migrations.Utilities.MigrationWriter.Write(ScaffoldedMigration scaffoldedMigration, Boolean rescaffolding, Boolean force, String name)
at System.Data.Entity.Migrations.AddMigrationCommand.WriteMigration(String name, Boolean force, ScaffoldedMigration scaffoldedMigration, Boolean rescaffolding)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Unable to add '201506111233565_Initial.vb'. A file with that name already exists.
当我查看解决方案资源管理器时(刷新后)文件就在那里,但是从项目中排除。
当我删除MigrationsDirectory =“Identity \ Migrations”时,它运行正常(但正在\ Migrations中创建迁移文件)
我不认为这是相关的,但要确定:我也在使用Team explorer 2013对此项目进行源代码控制。
答案 0 :(得分:10)
您的文件夹名称格式错误,因此EF认为它是一个文件。尝试在此处使用单个反斜杠:-MigrationsDirectory Identity\Migrations
而不是-MigrationsDirectory Identity\\Migrations