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?
This can be easily done by deleting your Migrations folder and dropping your database; at that point you can create a new initial migration, which will contain your entire current schema. It's also possible to reset all migrations and create a single one without losing your data.
Don't know if this is the official method. But here's how I did it.
Deleted matching row from __MigrationHistory
DELETE FROM __MigrationHistory WHERE MigrationId='201210271944168_AddLogTable'
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