sequelize.js - 在 sequilize.js 中使用对象数组时出错?
问题描述
当我试图编译这段代码时
const UserDetail = connection.define('user_detail', {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.INTEGER,
autoIncrement: true,
},
name: {
type: Sequelize.STRING,
allowNull: false,
len: [6, 50],
},
about: {
type: Sequelize.TEXT,
allowNull: false,
},
position: {
type: Sequelize.STRING,
allowNull: false
},
birth: [{
year: {
type: Sequelize.INTEGER,
allowNull: false
},
location: {
type: Sequelize.TEXT,
allowNull: false
},
}]
});
它抛出这个错误
Unhandled rejection SequelizeDatabaseError: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[object Object], `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, P' at line 1
创建对象数组的好方法是什么?我用谷歌搜索了这个问题,但找不到解决方案,而 Stack Overflow 上的上一个问题我没有得到。
解决方案
如果您希望它是一个“数组”,您可以使用不同的相关表,或者您可以将字段定义为:
birth_year: {
type: Sequelize.INTEGER,
allowNull: false,
},
birth_location: {
type: Sequelize.TEXT,
allowNull: false,
},
推荐阅读
- django - 在elpy(Django命令)中从默认python解释器切换到ipython
- tfs - 无法访问工作项跟踪服务 Azure DevOps Extensions
- javascript - Angular. Get server response in catchError
- swift - Swift 中带有闭包的模棱两可的方法重载,但仅当闭包返回一个值时
- filter - ffmpeg 剪切视频 + 重新缩放预览(代理)
- groovy - (Groovy) 查找所有包含特定用户组的 Confluence 空间
- hashicorp-vault - Vault 数据库机密引擎忽略非默认端口
- powershell - 在 foreach 中使用演员表
- javascript - 在 Wkwebview Cordova ios 14 中打开 Websql 数据库
- pyspark - 在pyspark中,Alteryx右外自连接等于什么?