Open Closed

PostgreSQL DateTime - with time zone to without time zone #4988


User avatar
1
Leonardo.Willrich created
  • ABP Framework version: v7.2.0.rc2
  • UI type: Blazor
  • DB provider: EF Core - PostgreSQL
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

Hi,

After having done the upgrade from 5.3 to 7.2 rc, I have added a migration in the EF project and have noticed that all DateTime fields are being changed from "with time zone" to "without time zone". Is it a problem? How can I avoid it? Is there some property to set?

In CreateDbContext class, I have this option"

         // https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

Here is an example:

 migrationBuilder.AlterColumn<DateTime>(
                name: "LastModificationTime",
                table: "SaasTenants",
                type: "timestamp without time zone",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "timestamp with time zone",
                oldNullable: true);

10 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please create a new 7.2 template project with npgsql

    And global search for the EnableLegacyTimestampBehavior keyword.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    MyProjectNameEntityFrameworkCoreModule and MyProjectNameDbContextFactory

  • User Avatar
    0
    Leonardo.Willrich created

    Hi Maliming,

    I have those properties, exacly like the template. Anyway, it is trying to convert the DateTime types in the DB.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think you can delete the previous migrations and re-create them.

    https://www.npgsql.org/efcore/release-notes/6.0.html#opting-out-of-the-new-timestamp-mapping-logic

  • User Avatar
    0
    Leonardo.Willrich created

    I did that multiple times, with the options or without the options, but it is still creating that code in the migration file.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    There must have a difference between your project and the template project.

    Can you check the template?

    or share a simple project liming.ma@volosoft.com

  • User Avatar
    0
    Leonardo.Willrich created

    Hi, I've sent an email with projects EntityFramework, Domain, and Domain.Shared.

    To create a new migration, I'm using Package Manager Console, selecting EntityFramework project in the combo-box, and then using this command: add-migration Migration_7.2.0 -context SBCDbContext

    It will create the code changing DateTime fields from "date with time zone" to "date without time zone".

  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi

    I suddenly realized that you need to remove AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); if you need date with time zone.

  • User Avatar
    0
    Leonardo.Willrich created

    Ok, I'll try it.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35