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);
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    MyProjectNameEntityFrameworkCoreModule and MyProjectNameDbContextFactory

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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".

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Leonardo.Willrich created

    Ok, I'll try it.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.