添加迁移文件名已存在 [英] Adding a migrations gives filename already exists

查看:103
本文介绍了添加迁移文件名已存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经启用了这样的迁移:

I have enabled migrations as such:

enable-Migrations -ProjectName ProjectOne -ContextTypeName MyIdentity.Config.MyIdentityContext -MigrationsDirectory Identity\\Migrations

我指定了上下文,因为它位于单独的命名空间中,并且我指定了目录,因为我想在其他目录中进行迁移。

I specified my context as it is in a separated namespace, and i specified the directory because i want to have the migrations in a different directory.

在启用了这种迁移之后,我在预期的位置获得了预期的配置文件(Identity\Migrations文件夹)(我删除了种子过程中的注释)

After enabling the migrations like this, i get the expected configuration file in the expected location (Identity\Migrations folder) (i removed the comments in the seed procedure)

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

在此之后,我创建了一个迁移:

After this I create a migration:

add-migration Initial

但是随后出现错误指出该文件已存在:

But then i get an error stating that the file already exists:

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.

当我在解决方案资源管理器中查看(刷新后)时,文件存在,但是从项目中排除。

When i look in the solution explorer (after refreshing) the file is there, but excluded from the project.

当我删除MigrationsDirectory = Identity\Migrations时,它工作正常(但正在\Migrations中创建迁移文件)

When I remove the MigrationsDirectory = "Identity\Migrations" it is working fine (but the migration file is being created in \Migrations)

我认为不相关,但是请确保:我也正在使用Team Explorer 2013对该项目进行源代码控制。

I dont think it is relevant but to be sure: I'm also using Team explorer 2013 for source control on this project.

推荐答案

您的文件夹名称格式错误,因此EF认为它是文件。尝试在此处使用单个反斜杠: -MigrationsDirectory Identity\Migrations 而不是 -MigrationsDirectory Identity\\Migrations

Your folder name is malformed so EF thinks it is a file. Try using a single backslash here: -MigrationsDirectory Identity\Migrations instead of -MigrationsDirectory Identity\\Migrations

这篇关于添加迁移文件名已存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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