添加迁移给出文件名已经存在
Adding a migrations gives filename already exists
我已经启用了这样的迁移:
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 对该项目进行源代码控制。
您的文件夹名称格式不正确,因此 EF 认为它是一个文件。尝试在此处使用单个反斜杠:-MigrationsDirectory Identity\Migrations
而不是 -MigrationsDirectory Identity\Migrations
我已经启用了这样的迁移:
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 对该项目进行源代码控制。
您的文件夹名称格式不正确,因此 EF 认为它是一个文件。尝试在此处使用单个反斜杠:-MigrationsDirectory Identity\Migrations
而不是 -MigrationsDirectory Identity\Migrations