In case we have created a table and forget to include a foreign key, we can do it by creating a new migration and then running it. The following code shows how to do it:
knex.schema.table('employees', function (table) {
table.bigInteger('deptno').references('id').inTable('Depts')
});
The above code adds a column deptno as a foreign key in the table named "Employees", that refers a column "ID" from the Dept table.
Happy Coding!!!.
Comments