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.
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.
When I remove the MigrationsDirectory = "Identity\Migrations" it is working fine (but the migration file is being created in \Migrations)
I dont think it is relevant but to be sure: I'm also using Team explorer 2013 for source control on this project.
Delete your Migrations folder. Create a new migration and generate a SQL script for it. In your database, delete all rows from the migrations history table. Insert a single row into the migrations history, to record that the first migration has already been applied, since your tables are already there.
Add-Migration: Creates a new migration class as per specified name with the Up() and Down() methods. Update-Database: Executes the last migration file created by the Add-Migration command and applies changes to the database schema.
From the Tools menu, select NuGet Package Manager > Package Manager Console. The enable-migrations command creates a Migrations folder in the ContosoUniversity project, and it puts in that folder a Configuration. cs file that you can edit to configure 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With