我将Node.js和TypeORM与MySQL一起使用,但是错误显示了MariaDB,我不知道为什么。我试图在用户实体中使用数组,这一定是错误
误差
QueryFailedError: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
for the right syntax to use near '' at line 1",
sqlState: '42000',
index: 0,
sql: 'ALTER TABLE `user` ADD `favorites` text NOT NULL DEFAULT '
},
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1",
sqlState: '42000',
index: 0,
sql: 'ALTER TABLE `user` ADD `favorites` text NOT NULL DEFAULT '
}导致错误的列:
@Column({ type: "simple-array", default: [] })
favorites: string[];
@Column({ type: "simple-array", default: [] })
cart: string[];发布于 2022-10-15 18:49:44
在mysql中,列类型text不能有默认值。删除列选项中的default参数,查询就会正常工作。
如果仍然希望设置任何默认值,则可以编写本机mysql触发器,或者在插入数据库后使用typeorm @AfterInsert钩子来设置列cart或favorites的值。
https://stackoverflow.com/questions/74072753
复制相似问题