使用Sequelize(用于Node.js的ORM),我正在尝试向数据类型为'DECIMAL'的表添加一列。我已经能够将其他列添加到具有DATE和STRING的其他数据类型的其他相同表中,但是此changeColumn函数将不会执行。相反,当我尝试命令sequelize db:migrate时,我在'category'中得到'ERROR:Unknown column'default_price'。我对开发非常陌生,因此我对Sequelize的了解还很少。
I run this command:
L05HandsOn>sequelize db:migrate
Sequelize CLI [Node: 8.11.4, CLI: 5.4.0, ORM: 4.43.0]
Loaded configuration file "config\config.json".
Using environment "development".
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules\sequelize\lib\sequelize.js:242:13
File: _current.json does not match pattern: /\.js$/
File: _current_bak.json does not match pattern: /\.js$/
File: _current.json does not match pattern: /\.js$/
File: _current_bak.json does not match pattern: /\.js$/
File: _current.json does not match pattern: /\.js$/
File: _current_bak.json does not match pattern: /\.js$/
== 2-category_Decimal_migration: migrating =======
[#0] execute: changeColumn
ERROR: Unknown column 'default_price' in 'category
My migration.js file looks like this:
'use strict';
var Sequelize = require('sequelize');
/**
* Actions summary:
*
* changeColumn "default_price" on table "category"
*
**/
var info = {
"revision": 2,
"name": "category_Decimal_migration",
"created": "2019-05-17T01:56:58.412Z",
"comment": ""
};
var migrationCommands = [{
fn: "changeColumn",
params: [
"category",
"default_price",
{
"type": Sequelize.DECIMAL(2, 2),
"field": "default_price",
"allowNull": false
}
]
}];
module.exports = {
and so on ...
When I run the 'sequelize db:migrate' command I expect to see
```[#0] execute: changeColumn
2-category_Decimal_migration: migrated (0.XXXs)```
答案 0 :(得分:0)
在这种情况下,所需的修复是在changeColumn之前运行addColumn命令-我试图更改不存在的列。由于auto-Sequelize命令以迁移文件的形式在后台进行了大量更改,因此按顺序执行文件创建步骤很重要-Sequelize不会准确地告诉您您未按顺序进行该步骤,但是我认为创建新的迁移文件。这可能会产生误导,因为如果一切就绪,最终可能会进行迁移。在这种情况下,由于用户错误,无法按照模型创建步骤的基本顺序执行迁移。