7

I have a table something like this:

Table: Deal Columns: Id int, deal int[]

Each entry in deal array references some other table id. How can we create the migration for the structure? Also, how can we create array column in knex for postgres.

2 Answers 2

21

You can use the specificType method for that:

knex.schema.createTable('deal', function(t) {
  t.increments()
  t.specificType('deal', 'INT[]')
})
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks. Also, How we define references for each deal? For ex: knex.integer('deal').references('user.id')
You want to add a foreign key to a table?
No, In integer array, I want to add foriegn key.
Just chain .references('user.id') to the specificType() call.
Incase anyone stumbles into this. It's not yet possible to define references for such a column. See this answer for more.
2
knex.schema.createTable('deal', function(t) 
{ 
    t.increments(),
    t.specificType('deal', 'integer ARRAY')
})

One can like this aswell.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.