.Net Core Or ABP 使用PgSQL迁移时Invalid Cast Exception: Cannot write DateTime with Kind=Local to PostgreSQL

发布时间 2023-09-05 22:44:20作者: 含泪拒绝王阿姨i

解决方法

添加忽略:AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);

using Acme.BookStore.EntityFrameworkCore;
using System;
using Volo.Abp.Autofac;
using Volo.Abp.Caching;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Modularity;

namespace Acme.BookStore.DbMigrator;

[DependsOn(
    typeof(AbpAutofacModule),
    typeof(AbpCachingStackExchangeRedisModule),
    typeof(BookStoreEntityFrameworkCoreModule),
    typeof(BookStoreApplicationContractsModule)
    )]
public class BookStoreDbMigratorModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpDistributedCacheOptions>(options => { options.KeyPrefix = "BookStore:"; });
        AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
    }
}

重新执行迁移即可!