Sequelize Migration NodeJS

Nika Roffy

I'm new to the sequelize and migrations. I want to take a foreign key from another table but I'm doing it wrong and I don't know why.

Any suggestions, please?

  *module.exports = {
  up: async (queryInterface, Sequelize) => {
    return queryInterface.createTable('comments',{
      topicid : {
        type:Sequelize.INTEGER,
        foreignKey : true
      },
      commentid : {
        type : Sequelize.INTEGER,
        primaryKey:true,
        autoIncrement:true,
      },
      comment : {
        type : Sequelize.STRING
      }
    })
  },

  down: async (queryInterface, Sequelize) => {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
  }
};*
arulmani venkatesh
'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('comments', {
      commentid: {
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      topicid: {
        foreignKey: true,
        references: {
          model: '<name_of_the_model>',
          key: '<name_of_the_key>'
        },
        type: Sequelize.INTEGER
      },
      comment: {
        type: Sequelize.STRING
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Products');
  }
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related