英文:
How to create a PostgreSQL table with column of type array using Fluentmigrator in C#
问题
这是您要翻译的内容:
"I might be overlooking something simple, I'm pretty novice with Fluentmigrator, but is it possible to create a table, using Fluentmigrator in C# code, that has a column of type array such as TEXT []?
Here is an example using SQL Syntax for comparison of the goal, with the column 'arrt' as the target column to create:
CREATE TEMPORARY TABLE IF NOT EXISTS array_test (
id SERIAL,
is_active BOOLEAN,
arrt TEXT[]
);
I tried checking the list of available methods through Visual Studio intelli-sense, on the WithColumn() method but this isn't giving me any luck. Also, although I am not sure I looked in the right place I did try going through the list of types here, which didn't show any indications I could tell that it is supported.
英文:
I might be overlooking something simple, I'm pretty novice with Fluentmigrator, but is it possible to create a table, using Fluentmigrator in C# code, that has a column of type array such as TEXT []?
Here is an example using SQL Syntax for comparison of the goal, with the column 'arrt' as the target column to create:
CREATE TEMPORARY TABLE IF NOT EXISTS array_test (
id SERIAL,
is_active BOOLEAN,
arrt TEXT[]
);
I tried checking the list of available methods through Visual Studio intelli-sense, on the WithColumn()
method but this isn't giving me any luck.
Also, although I am not sure I looked in the right place I did try going through the list of types here, which didn't show any indications I could tell that it is supported.
答案1
得分: 0
根据您提供的链接以及我自己的搜索结果,似乎标准的FluentMigrator方法无法实现此操作。
但是,您可以在迁移中运行SQL脚本。虽然这不是最佳实践,但在某些情况下非常有帮助。在这里,您可以看到一些示例,其中包括"Execute Expression"部分。
Execute.Script("myscript.sql");
Execute.EmbeddedScript("UpdateLegacySP.sql");
Execute.Sql("DELETE TABLE Users");
另外,您还可以从FluentMigrator仓库创建一个分支,并自己添加这些方法。不过,这样做可能会难以处理新的官方更新。
英文:
Based on link you provided and some search by myself seems like standard FluentMigrator methods can't do it.
But you can run sql script from your migration. Not the best practice, but in some cases is very helpful. Here you can see some examples. Execute Expression section.
Execute.Script("myscript.sql");
Execute.EmbeddedScript("UpdateLegacySP.sql");
Execute.Sql("DELETE TABLE Users");
Also you can make branch from FluentMigrator repo and add this methods by yourself. But it will be hard to handle new official updates.
答案2
得分: 0
这部分翻译如下:
This worked for me:
Create.Table("tablename")
.WithColumn("columnname").AsCustom("TEXT[]").Nullable();
英文:
This worked for me:
Create.Table("tablename")
.WithColumn("columnname").AsCustom("TEXT[]").Nullable();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论