gpt4 book ai didi

javascript - DataTypes.DECIMAL 导致可能导致错误 : 'Unknown column' in Sequelize auto-migration command

转载 作者:行者123 更新时间:2023-11-29 16:01:22 25 4
gpt4 key购买 nike

使用 Sequelize(Node.js 的 ORM),我尝试向数据类型为“DECIMAL”的表添加一列。我已经能够将其他列添加到具有其他 DATE 和 STRING 数据类型的其他相同表中,但此 changeColumn 函数将不会执行。相反,当我尝试命令sequelize db:migrate 时,我收到“错误:‘类别’中的未知列‘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)```

最佳答案

在这种情况下,需要的修复是在changeColumn之前运行addColumn命令——我试图更改不存在的列。由于 auto-Sequelize 命令以迁移文件的形式执行大量幕后更改,因此按顺序遵循文件创建步骤非常重要 - Sequelize 不会准确地告诉您您不按顺序执行了该步骤,但会我认为创建新的迁移文件。这可能会产生误导,因为如果一切就绪,迁移最终可能会被迁移。在这种情况下,由于用户错误地执行了模型创建步骤的基本顺序,因此无法执行迁移。

关于javascript - DataTypes.DECIMAL 导致可能导致错误 : 'Unknown column' in Sequelize auto-migration command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56179265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com