sequelize db:migrate挂起 [英] sequelize db:migrate hanging
问题描述
我正在尝试将模型迁移到我正在使用的postgress db,该数据库在本地托管,并且我确认它已启动并且运行良好.
I am trying to get my models to migrate to the postgress db I am using, which is hosted locally and I confirmed is up and running fine.
当我运行sequelize db:migrate
时,它说
Loaded configuration file "config\config.json"
Using environment "development"
然后什么也没有,我无法在控制台中输入任何内容,它一直坐在那里,直到我按Ctrl + C退出
then nothing, I can't type into the console or anything, it just sits there until I ctrl+C out of it
我尝试恢复对模型和迁移文件所做的所有更改,以防万一那里有问题并且无济于事.
I tried reverting all the changes I had made to the models and migrations files in case there was an issue there and it didn't help.
我还尝试通过npm重新安装sequelize-cli,但这也没有解决问题
edit: I also tried reinstalling the sequelize-cli through npm and that also did not fix the issue
在出现问题的情况下,这里是模型和迁移代码
here is the model and migration code in case that is the issue
型号:
'use strict';
module.exports = (sequelize, DataTypes) => {
const Contract = sequelize.define('Contract', {
buyout: DataTypes.DOUBLE,
collateral: DataTypes.DOUBLE,
contract_id: {type:DataTypes.INTEGER,allowNull: false,},
date_expired: {type:DataTypes.DATE,allowNull: false,},
date_issued: {type:DataTypes.DATE,allowNull: false,},
days_to_complete: DataTypes.INTEGER,
end_location_id: DataTypes.BIGINT,
for_corporation: DataTypes.BOOLEAN,
issuer_corporation_id: {type:DataTypes.INTEGER,allowNull: false,},
issuer_id: {type:DataTypes.INTEGER,allowNull: false,},
price: DataTypes.DOUBLE,
reward: DataTypes.DOUBLE,
start_location_id: DataTypes.BIGINT,
title: DataTypes.STRING,
type: {type:DataTypes.STRING,allowNull: false,},
volume: DataTypes.DOUBLE
});
Contract.associate = (models) => {
Contract.hasMany(models.ContractItem,{
foreignKey: 'contract_id'
});
};
return Contract;
};
迁移
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Contracts', {
buyout: {
type: Sequelize.DOUBLE
},
collateral: {
type: Sequelize.DOUBLE
},
contract_id: {
allowNull: false,
primaryKey: true,
type: Sequelize.INTEGER
},
date_expired: {
allowNull: false,
type: Sequelize.DATE
},
date_issued: {
allowNull: false,
type: Sequelize.DATE
},
days_to_complete: {
type: Sequelize.INTEGER
},
end_location_id: {
type: Sequelize.BIGINT
},
for_corporation: {
type: Sequelize.BOOLEAN
},
issuer_corporation_id: {
allowNull: false,
type: Sequelize.INTEGER
},
issuer_id: {
allowNull: false,
type: Sequelize.INTEGER
},
price: {
type: Sequelize.DOUBLE
},
reward: {
type: Sequelize.DOUBLE
},
start_location_id: {
type: Sequelize.BIGINT
},
title: {
type: Sequelize.STRING
},
type: {
allowNull: false,
type: Sequelize.STRING
},
volume: {
type: Sequelize.DOUBLE
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Contracts');
}
};
推荐答案
我们最近遇到了相同的问题,解决方法是在config.json中的环境配置中添加以下选项:
We recently encountered the same issue, the fix was to add the following option to our environment config in the config.json:
dialectOptions: {
ssl: true
}
当sequelize cli尝试验证SequelizeMeta表的架构时,它会运行一系列查询-其中一个查询是在没有上述选项的情况下运行约半小时后超时.
When the sequelize cli attempts to validate the schema of the SequelizeMeta table it runs a sequence of queries - one of these was timing out after about half an hour when run without the above option.
注意:我们的第一个迁移运行仍在创建表时仍在进行,因此跳过了验证.
Note: Our first migration run was still working as it was creating the table and so skipped the validation.
这篇关于sequelize db:migrate挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!