I am using typeORM to create a database using the following code
@Entity('Perfiles')
export class Perfil {
@PrimaryGeneratedColumn()
id: number;
@Column({
length: 270,
})
denominacion: string;
@OneToMany(() => Usuario, (usuario) => usuario.perfil)
usuarios: Usuario[];
}
@Entity('Usuarios')
export class Usuario {
@PrimaryGeneratedColumn()
id: number;
@Column({
length: 270,
})
userName: string;
@Column({
length: 270,
})
password: string;
@ManyToOne(() => Perfil, (perfil) => perfil.usuarios)
perfil: Perfil;
}
I did just as the documentation says this tipe of relation has to be done. Then, when trying to save a Usuario entity this is the query that typeORM makes
query failed: ALTER TABLE "Usuarios" ADD CONSTRAINT "FK_a8b47b700e6d61ba5fae9519726" FOREIGN KEY ("perfilId") REFERENCES "IWS2.0_dev.dbo.Perfiles"("id") ON DELETE NO ACTION ON UPDATE NO ACTION
error: QueryFailedError: Error: Could not create constraint or index. See previous errors.
Executing in the msql management studio this is the error that i get
Msg 1767, Level 16, State 0, Line 11
Foreign key 'FK_a8b47b700e6d61ba5fae9519726' references invalid table 'IWS2.0_dev.dbo.Perfiles'.
Msg 1750, Level 16, State 1, Line 11
Could not create constraint or index. See previous errors.
This happens with any type of relation i try to make. When I execute the query given by typeORM but without the quotes in “IWS2.0_dev.dbo.Perfiles” works just fine