Reputation: 542
I am using the new feature orphanedRowAction on TypeORM version 0.2.30 (2021-01-12):
@ChildEntity('business')
export default class BusinessGeolocation extends Geolocation {
@ManyToOne(
type => Business, business => business.geolocations, {
onDelete: 'CASCADE',
orphanedRowAction: "delete" // NEW
})
business!: Business;
}
Which works fine ( I can delete orphan rows) when I start my app using synchronized = true . However, I can't delete orphan rows with migrations=true. I could not find what changes on sql expression, when I start my app with migration instead.
Error: Run: error code 19: FOREIGN KEY constraint failed
query failed: DELETE FROM "forms" WHERE "formId" = ? -- PARAMETERS: [1]
What changes on sql expression when orphanedRowAction: "delete" ?
Upvotes: 1
Views: 720
Reputation: 542
It turns out for some reason I could not get the correct sql expression output, then I reset all my data, and it seems the main change for those who will create tables using migrations is this one:
ON DELETE NO ACTION ---> ON DELETE ON CASCADE
Upvotes: 1