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.
Delete the dist folder and re-run the server again.
I agree with Solomon ABOYEJI -- Deleting the dist folder, rerunning the server seemed to fix this problem for me (in my case it was setting all values of a certain column to an empty string which caused my server to hang because that column has a unique constraint)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With