Prerequisites
Please answer the following questions before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.
- What is your product version? 7.1.0
- What is your product type (Angular or MVC)? Angular
- What is product framework type (.net framework or .net core)? .net 6
If issue related with ABP Framework
- What is ABP Framework version? .net 6
If issue is about UI
- Which theme are you using? default
- What are the theme settings? default
other
DB : PostgreSQL
Npgsql version: 6.0.3
The project is starting. Only the changes to use PostgreSQL have been applied.
Exception message and stack trace:
Microsoft.EntityFrameworkCore.DbUpdateException
HResult=0x80131500
Mensaje = An error occurred while saving the entity changes. See the inner exception for details.
Origen = Microsoft.EntityFrameworkCore.Relational
Seguimiento de la pila:
en Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)
en Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable1 commandBatches, IRelationalConnection connection) en Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList
1 entries)
en Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList1 entriesToSave) en Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess) en Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__104_0(DbContext _, ValueTuple
2 t)
en Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func
3 verifySucceeded)
en Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
en Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
en Microsoft.EntityFrameworkCore.DbContext.SaveChanges()
en Abp.EntityFrameworkCore.AbpDbContext.SaveChanges()
en Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext3.SaveChanges() en SenerDemo.Migrations.Seed.Host.DefaultEditionCreator.CreateEditions() en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\Host\DefaultEditionCreator.cs: línea 31 en SenerDemo.Migrations.Seed.Host.DefaultEditionCreator.Create() en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\Host\DefaultEditionCreator.cs: línea 21 en SenerDemo.Migrations.Seed.Host.InitialHostDbBuilder.Create() en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\Host\InitialHostDbBuilder.cs: línea 16 en SenerDemo.Migrations.Seed.SeedHelper.SeedHostDb(SenerDemoDbContext context) en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs: línea 26 en SenerDemo.Migrations.Seed.SeedHelper.WithDbContext[TDbContext](IIocResolver iocResolver, Action
1 contextAction) en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs: línea 42
en SenerDemo.Migrations.Seed.SeedHelper.SeedHostDb(IIocResolver iocResolver) en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\Migrations\Seed\SeedHelper.cs: línea 18
en SenerDemo.EntityFrameworkCore.SenerDemoEntityFrameworkCoreModule.PostInitialize() en C:\Toni\GitLab\sener\src\SenerDemo.EntityFrameworkCore\EntityFrameworkCore\SenerDemoEntityFrameworkCoreModule.cs: línea 64
en Abp.Modules.AbpModuleManager.<>c.<StartModules>b__15_2(AbpModuleInfo module)
en System.Collections.Generic.List1.ForEach(Action
1 action)
en Abp.Modules.AbpModuleManager.StartModules()
en Abp.AbpBootstrapper.Initialize()
Esta excepción se generó originalmente en esta pila de llamadas: [Código externo]
Excepción interna 1: InvalidCastException: Cannot write DateTime with Kind=Local to PostgreSQL type 'timestamp with time zone', only UTC is supported. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.
Steps to reproduce the issue:"
I create a new solution via Abp Suite (Postgres)
Add Migration (Initial)
Run solution
I get above error.
Note:
If I put floowing code in Startup.cs error goes away. AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
This could be considered a bug?
Regards
3 Answer(s)
-
0
Hi,
Could you apply this fix https://stackoverflow.com/questions/69961449/net6-and-datetime-problem-cannot-write-datetime-with-kind-utc-to-postgresql-ty and see if it works ?
-
0
Hi, I added code follow on https://github.com/npgsql/doc/blob/main/conceptual/Npgsql/types/datetime.md/ and see it works ... public ProjectNameDbContext(DbContextOptions<ProjectNameDbContext> options) : base(options) { AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); } ...
-
0
Thanks @longviet