每次运行dotnet ef migrations add <migration_name>
时,创建的迁移都会重新创建所有数据库表。当然后尝试运行迁移时,我显然得到一条表已经存在的消息。
我错过了什么?我使用以下包裹;
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
我也在csproj
;
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
答案 0 :(得分:0)
如果数据库已存在且您想要对模型进行更改,请使用DropCreateDatabaseIfModelChanges<YourContextName>