Reputation: 2019
I am modifying a TypeOrm entity, and I broke the code somehow, but it's very difficult to get what's wrong.
All I have as a error message is :
[Nest] 31328 - 21/12/2021, 15:15:05 [TypeOrmModule] Unable to connect to the database. Retrying (1)... +269ms
QueryFailedError: 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 'array NOT NULL,
sessionId
varchar(36) NULL, PRIMARY KEY (id
)) ENGINE=InnoDB' at line 1at QueryFailedError.TypeORMError [as constructor] (/Users/arthurmehmetoglu/Development/CorpoSano/back/src/error/TypeORMError.ts:7:9)
at new QueryFailedError (/Users/arthurmehmetoglu/Development/CorpoSano/back/src/error/QueryFailedError.ts:9:9)
at Query.onResult (/Users/arthurmehmetoglu/Development/CorpoSano/back/src/driver/mysql/MysqlQueryRunner.ts:183:37)
at Query.execute (/Users/arthurmehmetoglu/Development/CorpoSano/back/node_modules/mysql2/lib/commands/command.js:36:14)
at PoolConnection.handlePacket (/Users/arthurmehmetoglu/Development/CorpoSano/back/node_modules/mysql2/lib/connection.js:456:32)
at PacketParser.onPacket (/Users/arthurmehmetoglu/Development/CorpoSano/back/node_modules/mysql2/lib/connection.js:85:12)
at PacketParser.executeStart (/Users/arthurmehmetoglu/Development/CorpoSano/back/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket. (/Users/arthurmehmetoglu/Development/CorpoSano/back/node_modules/mysql2/lib/connection.js:92:25)
at Socket.emit (node:events:390:28)
at addChunk (node:internal/streams/readable:315:12)
Any idea how could get more information on what TypeOrm is trying to perform here?
EDIT: After reading carefully the error message, the only clue is that the sessionId
is causing some trouble for some reason.
So I am sharing here are the entities that potentially involved:
@Entity()
export class Session extends BaseEntity {
@ManyToOne(() => Workout, (workout) => workout.sessions)
workout: Workout
@OneToMany(() => Performance, (performance) => performance.session, {
eager: true,
})
performances: Performance[]
constructor(partial: Partial<Session> = {}) {
super()
Object.assign(this, partial)
}
}
@Entity()
export class Performance extends BaseEntity {
@ManyToOne(() => Session, (session) => session.performances)
session: Session
@Column('int', { array: true })
sets: number[]
constructor(partial: Partial<Performance> = {}) {
super()
Object.assign(this, partial)
}
}
@Entity()
export class Workout extends BaseEntity {
@Column()
title: string
@ManyToOne(() => Program, (program) => program.workouts)
program?: Program
@OneToMany(() => Exercise, (exercise) => exercise.workout, { eager: true })
exercises?: Exercise[]
@OneToMany(() => Session, (session) => session.workout)
sessions?: Session[]
@Column({
type: 'set',
enum: WeekDays,
default: [],
})
scheduledDays?: WeekDays[]
constructor(partial: Partial<Workout> = {}) {
super()
Object.assign(this, partial)
}
}
Upvotes: 1
Views: 4940
Reputation: 2019
I solved it by modifying the Performance
entity as follow:
@Entity()
export class Performance extends BaseEntity {
@ManyToOne(() => Session, (session) => session.performances)
session: Session
@Column('simple-array')
sets: number[]
constructor(partial: Partial<Performance> = {}) {
super()
Object.assign(this, partial)
}
}
Upvotes: 0