Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

sequelize migration add column foreign key

queryInterface.addConstraint('table_name', {
  fields: ['column_name'],
  type: 'foreign key',
  name: 'custom_fkey_constraint_name', // optional
  references: {
    table: 'target_table_name',
    field: 'target_column_name'
  },
  onDelete: 'cascade',
  onUpdate: 'cascade'
});
 
PREVIOUS NEXT
Tagged: #sequelize #migration #add #column #foreign #key
ADD COMMENT
Topic
Name
5+6 =