DB Changes not applied while creating multi reference table

Hello Guys,

I am trying to create multi reference table between 2 sub tables, however I am running into an error. Need your help in trying to understand the issue.

Project is on NodeJS + MS SQL Server.

I have these 2 sub tables, instBuilding & instCourse as per images.

image image

I created a multi reference table ‘rooms’

image


image

While applying DB Changes i am getting error:

image

exports.up = function(knex) {

  return knex.schema

    .createTable('dbo.institute_instBuilding_rooms', async function (table) {

      table.integer('instBuilding_id').unsigned();

      table.foreign('instBuilding_id').references('buildingID').inTable('dbo.dbo.institute_instBuilding').onUpdate('CASCADE').onDelete('CASCADE');

      table.integer('instCourseID').unsigned();

      table.foreign('instCourseID').references('instCourseID').inTable('dbo.dbo.institute_instCourse');

    })

};

exports.down = function(knex) {

  return knex.schema

    .dropTable('dbo.institute_instBuilding_rooms')

};

You want each room to have a link to instBuilding & instCourse, right?

The general rule is this: after creating any new element in the database schema, apply the database change

  1. Make a complete schema update by clicking on the connection name and opening the context menu
  2. Create a regular rooms table - apply the changes
  3. Create the first multi-reference table inside “rooms” and apply the changes
  4. Then the same with the second

Thanks for your reply @vv-a2007
I created the tables as mentioned by you, however, the issue was still persisting. I tried removing the ‘dbo.’ prefix from the table names which seems to have solved the issue.
Thanks again for your help.

1 Like