gpt4 book ai didi

postgresql - TypeError : s. 替换不是函数

转载 作者:行者123 更新时间:2023-11-29 11:44:27 26 4
gpt4 key购买 nike

环境:

  • Postgres:10.2
  • 节点:6.11.0
  • 命令行界面:2.4.0
  • ORM:2.1.3

型号:

'use strict';
module.exports = function(sequelize, DataTypes) {
var test = sequelize.define('test', {
id: DataTypes.UUID,
type: DataTypes.STRING,
data: DataTypes.JSON,
}, {
'createdAt': {
type: Sequelize.DATE(3),
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3)'),
},
'updatedAt': {
type: Sequelize.DATE(3),
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)'),
},
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return test;
}

迁移:

'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.addColumn('test', {
test_col: {
type: Sequelize.JSONB
}
});
},
down: function(queryInterface, Sequelize) {
return queryInterface.removeColumn('test', 'test_col');
}
};

错误:

TypeError: s.replace is not a function
at Object.removeTicks (/node_modules/sequelize/lib/utils.js:329:14)
at Object.addTicks (/node_modules/sequelize/lib/utils.js:325:29)
at Object.quoteIdentifier (/node_modules/sequelize/lib/dialects/postgres/query-generator.js:835:22)
at Object.addColumnQuery (/node_modules/sequelize/lib/dialects/postgres/query-generator.js:182:19)
at QueryInterface.module.exports.QueryInterface.addColumn

最佳答案

用于迁移的语法不正确。 queryInterface.addcolumn 方法需要 3 个参数,而您只传递 2 个参数。参见 here .

public addColumn(table: String, key: String, attribute: Object, options: Object): Promise

'use strict';
module.exports = {
up: function(queryInterface, Sequelize) {
return queryInterface.addColumn(
'pages',
'group',
Sequelize.JSONB
);
},
down: function(queryInterface, Sequelize) {
return queryInterface.removeColumn('pages', 'group');
}
};

对于任何遇到 s.replace 错误的人来说,这基本上是因为您没有传递预期类型的​​参数。所以在上面的例子中,一个对象被作为第二个参数传递给 queryInterface.addColumn 而它期待一个 String 文字。阅读更多 here .

关于postgresql - TypeError : s. 替换不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48869975/

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