简体   繁体   中英

knex.js + pg specify varchar to be > 255

When creating a table in knex migrations, I have indicated a col as such:

table.string("content");

It defaults to varchar 255. I would like it to be able to hold more text. How do I indicate to knex that I want this to occur?

You can define the col in following way to set the length of the string:

    table.string("content", 1000)

This results to:

    content         character varying(1000)

Reference: http://knexjs.org/#Schema-string

There is also other way to do it:

table.text(columnName, [textType]);

Adds a text column, with optional textType for MySql text datatype preference where textType defaults to text .

PSQL text type description: variable unlimited length.

References:
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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM