Sequelize不创造外国专栏(postgres)

时间:2016-03-03 01:49:23

标签: postgresql sequelize.js

我正在尝试使用sequelize来创建一些表格(这不是生产),我知道如何通过基本的SQL命令来做到这一点,但我想弄清楚如何使用sequelize(在学校)

我试图通过这些命令创建三个表。

node_modules/.bin/sequelize model:create --name movies--attributes "title:string,description:string,image_url:string,year:integer,date_obtained:date,rating:integer,notes:text"
node_modules/.bin/sequelize model:create --name borrowers --attributes "firstname:string,lastname:string,email:string"
node_modules/.bin/sequelize model:create --name types --attributes "name:string"

然后我进入movies.js并更改关联

'use strict';
module.exports = function(sequelize, DataTypes) {
  var movies = sequelize.define('movies', {
    title: DataTypes.STRING,
    description: DataTypes.STRING,
    image_url: DataTypes.STRING,
    year: DataTypes.INTEGER,
    date_obtained: DataTypes.DATE,
    rating: DataTypes.INTEGER,
    notes: DataTypes.TEXT
  }, {
    classMethods: {
      associate: function(models) {
        movies.belongsToMany(models.borrowers);
        movies.belongsToMany(models.types);
      }
    }
  });
  return movies;
};

以及借用者.js

'use strict';
module.exports = function(sequelize, DataTypes) {
  var borrowers = sequelize.define('borrowers', {
    firstname: DataTypes.STRING,
    lastname: DataTypes.STRING,
    email: DataTypes.STRING
  }, {
    classMethods: {
      associate: function(models) {
        borrowers.hasMany(models.movies);
      }
    }
  });
  return borrowers;
};

和types.js

    'use strict';
module.exports = function(sequelize, DataTypes) {
  var types = sequelize.define('types', {
    name: DataTypes.STRING
  }, {
    classMethods: {
      associate: function(models) {
        types.hasMany(models.movies);
      }
    }
  });
  return types;
};

并运行

node_modules/.bin/sequelize db:migrate

但是电影中没有创建列(我希望像borrower_id和type_id这样的东西)。在另一个测试中,我尝试在电影中手动创建borrower_id,当我尝试插入时出现此错误

Unhandled rejection SequelizeDatabaseError: column "borrowerId" does not exist

所以它试图引用该列,但它没有被创建?任何帮助都将非常感激,我正在学习,显然缺少一些东西。

0 个答案:

没有答案