同步同步忽略对迁移文件的更新

时间:2018-11-29 08:19:24

标签: sequelize.js sequelize-cli

尽管显然缺少一些东西,但Sequelize才刚刚开始。在测试的过程中,似乎对我的模型的迁移文件进行了任何更改,都不会影响在测试过程中使用sequelize.sync调用的迁移-会有所帮助!

我的测试文件:

const expect = require('chai').expect;
const db = require('../db/models')
fs = require('fs')
const app = require('../index')
const request = require('supertest');
const Metric = db.Metric


describe('metric', function() {

  beforeEach((done) => {
    db.sequelize.sync({ force: true})
      .then(() => {
        done();
      })
  });


  it('can be saved', async function() {

    const result = await Metric.create({ name: '5km Run', unit: 'minutes' });
    expect(result.name).to.equal('5km Run');
    const all = await Metric.findAll();
    expect(all.length).to.be.equal(1);
});

我的模特:

'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Metrics', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      name: {
        type: Sequelize.STRING,
        allowNull: true
      },
      unit: {
        type: Sequelize.STRING,
        allowNull: false
      },
      goal: {
        type: Sequelize.INTEGER,
        allowNull: true
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Metrics');
  }
};

我运行测试时,终端始终弹出:

CREATE TABLE IF NOT EXISTS `Metrics` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);

我对“单位”和“目标”列的添加被完全忽略。即使我注释掉整个迁移文件,它也只能运行相同的早期版本!手动迁移到我的开发mysql数据库时,所做的更改工作正常。为了进行测试,我将其设置为在内存sqlite中。

谢谢!

0 个答案:

没有答案