我有一个类库项目,我的DbContext和迁移启用了以下配置文件:
<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>
在我使用此项目的迁移之前的某个时间,Get-Migrations命令总是返回给我:
PM> Get-Migrations -StartupProjectName "Data"
Retrieving migrations that have been applied to the target database.
201207012104355_Initial
201207012031234_Initial
201207012024250_Initial
问题是命令总是返回这些项,即使我删除Data.sdf或删除所有项目并创建新项目 . 我可以创建新数据库的唯一方法是将连接字符串中的数据库文件名从Data.sdf更改为Data1.sdf . 那么如何在不更改数据库名称的情况下重置迁移历史?
1 回答
不知道这是否是官方方法 . 但这就是我做到的 .
删除了迁移文件
从__MigrationHistory中删除了匹配的行
DELETE FROM __MigrationHistory WHERE MigrationId ='201210271944168_AddLogTable'