gpt4 book ai didi

mysql - TypeError : s. removeConstraint 时 replace 不是函数

转载 作者:行者123 更新时间:2023-11-29 05:48:21 28 4
gpt4 key购买 nike

我正在使用 sequelize 5.5.0 构建一个应用程序。我创建了一些模型;像 coursescoursecategory 是数据库中的一些表。我需要将foreing key courseCategory 添加到course 表...(一个类别有很多类(class))但是当我创建 migration 并使用 addConstraint() 添加 Constraint 时一切正常,但是当恢复时显示错误

我知道如果我在开始时创建约束我可以解决这个问题但在我的情况下我将迁移一个项目并且现有数据库中有很多记录。因此,例如在未来的情况下,如果我想创建一个约束并创建我的迁移,我将无法恢复它

之后我有像这样的类(class)模型..

const Course = sequelize.define('Course', {
//attributes
courseId:{
type: DataTypes.INTEGER.UNSIGNED,
allowNull : false,
autoIncrement: true,
primaryKey: true,
},
category:{
type: DataTypes.INTEGER.UNSIGNED,
allowNull:false,
defaultValue: 1
}
});



我的类(class)类别模型


const Coursecategory = sequelize.define('Coursecategory', {
//atributes
coursecategoryId:{
type: DataTypes.INTEGER.UNSIGNED,
allowNull : false,
autoIncrement: true,
primaryKey: true,
},
name:{
type: DataTypes.STRING,
allowNull:true
},
order:{
type: DataTypes.SMALLINT.UNSIGNED,
allowNull:false,
defaultValue: 0
}
}, {});

我的约束迁移就在这里...


up: (queryInterface, Sequelize) => {

return await queryInterface.addConstraint('courses', ['category'], {
type: 'foreign key',
name: 'courses_category_coursecategories_fk',
references: {
table: 'coursecategories',
field: 'coursecategoryId',
},
defaultValue: 0,
allowNull: true,
onDelete: 'no action',
onUpdate: 'no action',
})
},

down: async (queryInterface, Sequelize) => {

return await queryInterface.removeConstraint('courses', ['courses_category_coursecategories_fk'],{})

}


我希望迁移运行良好。我查看了 INFORMATION_SCHEMA 表,我的 key (courses_category_coursecategories_fk) 就在那里。但是发生了一些事情,我没有收到更多的日志..

ERROR: s.replace is not a function

最佳答案

removeConstraint 接受字符串作为第二个参数,而不是数组,参见 docs .应该像这样工作:

return await queryInterface.removeConstraint('courses','courses_category_coursecategories_fk')

关于mysql - TypeError : s. removeConstraint 时 replace 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57229541/

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