我已经启用了迁移,具体如下:
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进行源代码控制。