2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sequelizeでtoStringエラー

Posted at

sequelizeを使ってdb:migrateした時に,エラーが出て困った

ERROR: Cannot read property 'toString' of undefined

ファイル名も行数も出てなかったので地道に調べてた結果,migrate用のjsファイルのtypeがおかしいことが判明.

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('orders', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING
      },
      user_id: {
        type: Sequelize.INT
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('orders');
  }
};

Sequelize.INTは存在しなく,Sequelize.INTEGERと書かなければいけないらしい
sequelize-cliを使ってgenerateしたときにエラーチェックで弾いてほしかった・・・

ほかにも,Sequelize.FLOATSequelize.DOUBLEは存在しないようなので注意が必要

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?