Search
 
SCRIPT & CODE EXAMPLE
 

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'
});
Comment

sequelize migration add column

module.exports = {
    up: (queryInterface, Sequelize) => {
        return queryInterface.sequelize.transaction((t) => {
            return Promise.all([
                queryInterface.addColumn('table_name', 'field_one_name', {
                    type: Sequelize.STRING
                }, { transaction: t }),
                queryInterface.addColumn('table_name', 'field_two_name', {
                    type: Sequelize.STRING,
                }, { transaction: t })
            ])
        })
    },

    down: (queryInterface, Sequelize) => {
        return queryInterface.sequelize.transaction((t) => {
            return Promise.all([
                queryInterface.removeColumn('table_name', 'field_one_name', { transaction: t }),
                queryInterface.removeColumn('table_name', 'field_two_name', { transaction: t })
            ])
        })
    }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: use style in react 
Javascript :: send mail, nodemailer, nodemailer, mailer, nodemailer npm 
Javascript :: reducer in react example 
Javascript :: how to add number in string in javascript 
Javascript :: promise.all vs promise.allsettled 
Javascript :: inline styling in react 
Javascript :: space in string using if in jquery 
Javascript :: how to insert html into javascript 
Javascript :: cart page route in shopify 
Javascript :: how to hide ascending descending icons in datatable js 
Javascript :: react webpack config example 
Javascript :: getDataSnapshotFirebase 
Javascript :: repeat array in js 
Javascript :: store images in mongoose 
Javascript :: axios patch 
Javascript :: inheritance in javascript 
Javascript :: js fetch api 
Javascript :: exporting a class 
Javascript :: jquery before submit 
Javascript :: clear the command prompt node 
Javascript :: nodejs open file 
Javascript :: node js check if called from command line 
Javascript :: mongoBD $inc operator 
Javascript :: how to make a confirm popup in vue 
Javascript :: primitive and non primitive data types in javascript 
Javascript :: EACCES: permission denied 
Javascript :: Javascript Show HTML Elements 
Javascript :: javascript parse date dd/mm/yyyy hh:mm:ss 
Javascript :: mongodb limit find node 
Javascript :: js how to sort strings in array 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =