【问题标题】:Sequelize Migration NodeJS续集迁移NodeJS
【发布时间】:2020-11-09 14:14:38
【问题描述】:

我是续集和迁移的新手。 我想从另一个表中取出一个外键,但我做错了,我不知道为什么。

有什么建议吗?

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

【问题讨论】:

    标签: node.js sequelize.js


    【解决方案1】:
    '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');
      }
    };
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2018-01-29
      • 2014-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多