I have developed a ASP.NET Core MVC application which was connecting to a SQL Server database. Now, I changed the target database to PostgreSQL by following below steps
Step #1 - Changed the connection string
Step #2 - Replaced the .HasColumnType("INTEGER")
with .HasColumnType("BOOLEAN")
Step #3 - ran the command dotnet ef database update
But only __EFMigrationsHistory
table got created.
AspNetRoleClaims, AspNetRoles, AspNetUserClaims
and other required tables are not created.
I suspect there's something wrong in this code:
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>();
These are my packages
<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>
Resolved
After adding below nuget packagae things worked!!
dotnet add package Microsoft.EntityFrameworkCore.Design