TypeORM sets relation to null when reloading NestJS application

Viewed 139

When I reload my NestJS application the foreign key gets set to null.

User table:

@Entity()
export class User {
 @PrimaryGeneratedColumn()
 @OneToMany(() => Marker, (marker) => marker.user)
 @OneToMany(() => Vote, (vote) => vote.user)
 id: number;
 
 @Column
 name: string
}

Vote table:

@Entity()
export class Vote {
 @PrimaryGeneratedColumn()
 id: number
 
 @ManyToOne(() => User, (user) => user.id)
 user: User;
}

When I try the application everything works and in the vote table the user gets set and everything works. But when I restart the application the foreign key user from the table vote gets set to null. There are no error messages or warnings so I'm confused to what is going on.

1 Answers

Delete the dist folder and re-run the server again.

Related