当我尝试添加迁移时,出现以下错误。
我在用
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="MySql.EntityFrameworkCore" Version="6.0.0" />
例外情况是,
PM> Add-Migration InitialCreate
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.3 initialized 'ApplicationDbContext' using provider 'MySql.EntityFrameworkCore:6.0.0+MySQL8.0.28' with options: None
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource'.
此文件中提供完整的错误日志。
提前感谢!
哎呀!我忘记更新答案了。我从MySql.EntityFrameworkCore转到Pomelo.EntityFrameworkCore.MySql。
现在我可以执行以下添加迁移和更新数据库命令
您缺少对Microsoft.EntityFrameworkCore
的引用。
尝试添加以下参考:
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />