“Sequellize Migration Add Column” Kode Jawaban

Sequellize Migrasi Tambahkan Kolom Asing Kunci

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

Sequellize 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 })
            ])
        })
    }
};
Jeff Le

Jawaban yang mirip dengan “Sequellize Migration Add Column”

Pertanyaan yang mirip dengan “Sequellize Migration Add Column”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya