knex.js + pg specify varchar to be > 255

kuanb picture kuanb · Mar 5, 2016 · Viewed 8k times · Source

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?

Answer

Sanjeev Kumar Pandit picture Sanjeev Kumar Pandit · Aug 16, 2016

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