Hi,
I'm trying to get AspnetZero working with Postgres.
What I have done.
1)Uninstall the package Microsoft.EntityFrameworkCore.SqlServer 2)add Npgsql.EntityFrameworkCore.PostgreSQL & Npgsql.EntityFrameworkCore.PostgreSQL.Design 3)Modified the DbContext Configure method to use UseNpgsql 4)Added fix for max char error
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
foreach (var property in entityType.GetProperties())
{
// max char length value in sqlserver
if (property.GetMaxLength() == 67108864)
// max char length value in postgresql
property.SetMaxLength(10485760);
}
}
}
- changed the connection string in appsettings.json
When I ran the migration it fails.
PM> Update-Database
Applying migration '20170623075109_AspNetZero_V4_1_Changes'.
Failed executing DbCommand (18ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
UPDATE AbpEditions SET Discriminator = 'SubscribableEdition'
Npgsql.PostgresException (0x80004005): 42P01: relation "abpeditions" does not exist
any help is appreciated.
3 Answer(s)
-
2
Hi @geowikiapps, did you read following doc: <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/EF-Core-PostgreSql-Integration">https://aspnetboilerplate.com/Pages/Doc ... ntegration</a>
I think you missed this line:
"Remove all migration classes in the *.EntityFrameworkCore/Migrations folder, because Npgsql.EntityFrameworkCore.PostgreSQL will add some of its own configuration"
-
1
30-07-2019
Doc: https://aspnetboilerplate.com/Pages/Documents/EF-Core-PostgreSql-Integration
But, You don't need this now:
To prevent EF Core from calling Program.BuildWebHost(), rename BuildWebHost. For example, change it to InitWebHost.
This is misleading:
Delete the *.EntityFrameworkCore/Migrations folder, because Npgsql.EntityFrameworkCore.PostgreSQL will add some of its own configuration to work with Entity Framework Core.
It should be like this:
Delete the *.EntityFrameworkCore/Migrations folder's Migration classes. Don't delete Seed folder. Because Npgsql.EntityFrameworkCore.PostgreSQL will add some of its own configuration to work with Entity Framework Core.
-
0
Hello, I'm trying to do the same and deleted the .EntityFrameworkCore/Migrations folder's Migration classes but not the Seed folder and it's contents. Add-Migration and Update-Database went well:
PM> add-migration Initial_Migration Build started... Build succeeded. To undo this action, use Remove-Migration. PM> update-database Build started... Build succeeded. Applying migration '20200122140256_Initial_Migration'. Done.
But after launching the host I get this error:
Npgsql.PostgresException HResult=0x80004005 Message=42P01: Relation »AbpEditions« existiert nicht Source=Npgsql
What am I doing wrong? Thanks for help!