I have this table:
BookUnit
-------------------
id PK
unit PK
sequence PK
book_id FK
So, i can have records with data:
id: 1
unit: 1
sequence: 1
id: 2
unit: 1
sequence: 2
but i can't have more than one repetead:
id: 3 unit: 1 sequence: 2
So, i need to create a composed primary key with id,sequence and unit.
I try this way:
class BookUnitSchema extends Schema {
up () {
this.create('book_unit', (table) => {
table.increments()
table.integer('book_id').references('id').inTable('books').notNullable()
table.integer('unit').notNullable().primary()
table.integer('sequence').notNullable().primary()
table.string('description')
table.integer('qt_question')
table.boolean('status').defaultTo(false)
table.integer('user_id').references('id').inTable('users')
table.timestamps()
})
}
down () {
this.drop('book_unit')
}
}
But i'm getting:
error: multiple primary keys for table "book_unit" are not allowed
I don't find in docs example with more than one primary key...