SQL Server 到 postgres - 未创建身份表

问题描述 投票:0回答:1

我开发了一个连接到 SQL Server 数据库的 ASP.NET Core MVC 应用程序。现在,我按照以下步骤将目标数据库更改为 PostgreSQL

  • 步骤 #1 - 更改连接字符串

  • 步骤 #2 - 将

    .HasColumnType("INTEGER")
    替换为
    .HasColumnType("BOOLEAN")

  • 步骤#3 - 运行命令

    dotnet ef database update

但只创建了

__EFMigrationsHistory
表。

AspNetRoleClaims, AspNetRoles, AspNetUserClaims
以及其他所需的表未创建。

我怀疑这段代码有问题:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'IdentityContextConnection' not found.");

builder.Services.AddDbContext<IdentityContext>(options => options.UseNpgsql(connectionString));

builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false)
  .AddEntityFrameworkStores<IdentityContext>();

这些是我的包裹

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
        <None Include="..\.editorconfig" Link=".editorconfig" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
        <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.12" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="7.0.11" />
        <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
    </ItemGroup>
</Project>
postgresql asp.net-core-mvc migration database-migration
1个回答
0
投票

已解决

添加以下 nuget 包后一切正常!!

dotnet 添加包 Microsoft.EntityFrameworkCore.Design

© www.soinside.com 2019 - 2024. All rights reserved.