Search code examples
node.jspostgresqlknex.js

Default value in Knex migration for an specific type of text array not working


I am creating a database migration using Knex (v0.19.5) and PostgreSQL (v10.1) but when I try to set the default value to a TEXT array column it gives me a malformed array literal error.

table.specificType('test', 'TEXT[]').defaultTo(['foo', 'bar']);

This is the error message

Array value must start with "{" or dimension information.

error: malformed array literal: "foo,bar"

Maybe I am missing something but I can't get it to work and I can't find anything useful in their official docs.


Solution

  • I finally solved it by simply setting the array into a literal string.

    table.specificType('test', 'TEXT[]').defaultTo('{\'\'foo\'\',\'\'bar\'\'}');