You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用C#的FluentMigrator创建带数组类型列的PostgreSQL表

在FluentMigrator中创建带PostgreSQL TEXT[]数组列的表

可以实现,FluentMigrator没有直接提供数组类型的内置方法,但可以通过指定自定义SQL类型来达成需求。以下是对应你目标SQL的C#迁移代码:

using FluentMigrator;

[Migration(20240520120000)] // 替换为你的迁移版本号
public class CreateArrayTestTable : Migration
{
    public override void Up()
    {
        // 创建临时表的写法
        Create.Table("array_test")
            .WithOptions().Temporary()
            .WithColumn("id").AsInt32().Identity().PrimaryKey() // 对应PostgreSQL的SERIAL类型
            .WithColumn("is_active").AsBoolean()
            .WithColumn("arrt").AsCustom("TEXT[]"); // 手动指定TEXT[]数组类型
    }

    public override void Down()
    {
        Delete.Table("array_test");
    }
}

关键说明

  • PostgreSQL的SERIAL类型,用AsInt32().Identity()来模拟,FluentMigrator会自动适配生成对应数据库的自增序列逻辑
  • 对于FluentMigrator未内置的数据库特定类型(比如TEXT[]数组),直接通过AsCustom("TEXT[]")指定原生类型即可
  • 临时表需要通过.WithOptions().Temporary()来声明

内容的提问来源于stack exchange,提问作者mp_in_training

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 16:00:59