While working on a TypeOrm entity, I encountered an issue and now I'm struggling to figure out what went wrong.
The error message I received 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]
at new QueryFailedError
at Query.onResult
at Query.execute
at PoolConnection.handlePacket
at PacketParser.onPacket
at PacketParser.executeStart
at Socket.
at Socket.emit
at addChunk
I need help in understanding what operations TypeOrm is attempting here. Any suggestions?
EDIT: Upon closer inspection of the error message, it seems like the sessionId
field might be causing the issue for some reason.
Let's take a look at the entities 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)
}
}