How to reset database migrations using EF code first?

.net, c#, ef-code-first, entity-framework, entity-framework-migrations

Solution

Don't know if this is the official method. But here's how I did it.

- Deleted migration file

Deleted matching row from __MigrationHistory

DELETE FROM __MigrationHistory WHERE MigrationId='201210271944168_AddLogTable'

Problem

I have a class library project with my DbContext and migration enabled with following config file: ``` <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </configSections> <connectionStrings> <add name="DataContext" connectionString="Data Source=Data.sdf" providerName="System.Data.SqlServerCe.4.0" /> </connectionStrings> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"> <parameters> <parameter value="System.Data.SqlServerCe.4.0" /> </parameters> </defaultConnectionFactory> </entityFramework> </configuration> ``` Some time before I played with migrations for this project and Get-Migrations command always returns following to me: ``` PM> Get-Migrations -StartupProjectName "Data" Retrieving migrations that have been applied to the target database. 201207012104355_Initial 201207012031234_Initial 201207012024250_Initial ``` The problem is that command always returns these items even if I delete Data.sdf or delete all project and make new one. The only way I can create new database is changing database file name in connection string from Data.sdf to Data1.sdf for example. So how can i reset migration history without changing database name?

Original source