knex.js + pg 指定 varchar > 255
knex.js + pg specify varchar to be > 255
在 knex 迁移中创建 table 时,我指定了这样一个列:
table.string("content");
它默认为 varchar 255。我希望它能够容纳更多文本。我如何向 knex 表明我希望发生这种情况?
您可以通过以下方式定义列来设置字符串的长度:
table.string("content", 1000)
结果为:
content character varying(1000)
还有其他方法:
table.text(columnName, [textType]);
添加文本列,为 MySql 文本数据类型首选项提供可选的文本类型,其中 文本类型默认为文本。
PSQL文本类型描述:变量无限制长度。
参考文献:
http://knexjs.org/#Schema-text
https://www.postgresql.org/docs/9.1/datatype-character.html
https://chartio.com/resources/tutorials/understanding-strorage-sizes-for-mysql-text-data-types/
在 knex 迁移中创建 table 时,我指定了这样一个列:
table.string("content");
它默认为 varchar 255。我希望它能够容纳更多文本。我如何向 knex 表明我希望发生这种情况?
您可以通过以下方式定义列来设置字符串的长度:
table.string("content", 1000)
结果为:
content character varying(1000)
还有其他方法:
table.text(columnName, [textType]);
添加文本列,为 MySql 文本数据类型首选项提供可选的文本类型,其中 文本类型默认为文本。
PSQL文本类型描述:变量无限制长度。
参考文献:
http://knexjs.org/#Schema-text
https://www.postgresql.org/docs/9.1/datatype-character.html
https://chartio.com/resources/tutorials/understanding-strorage-sizes-for-mysql-text-data-types/