Knex: Create migration with FOREIGN KEY Knex: Create migration with FOREIGN KEY sql sql

Knex: Create migration with FOREIGN KEY


This might come a little late but the error is because:

table.bigInteger('AddressId')    .unsigned()    .index()    .inTable('Address')    .references('id');

Should be written:

table.bigInteger('AddressId')    .unsigned()    .index()    .references('id')    .inTable('Address');

The inTable function only exists after calling references as explained in the documentation http://knexjs.org/#Schema-inTable

Sets the "table" where the foreign key column is located after callingcolumn.references.