Found error in chapter16 regarding Deleting acronyms

Hello ,

I found the error in chapter16 regarding deleting acronyms as below.
I tried to remove mysql image and add it again , then build vapor project .
Also checking the code by going through every concern files, but still get the error.

{“error”:true,“reason”:“Cannot delete or update a parent row: a foreign key constraint fails (vapor.acronym_category, CONSTRAINT acronym_category_ibfk_1 FOREIGN KEY (acronymID) REFERENCES acronyms (id))”}

@thammaporn it’s because you have a category relationship set up with that acronym. The new version of the book will show you how to remove that and it also shows you how to set up the DB to do a cascade delete to automatically remove the relationship. It’s in the online repo here

Thanks for your advice .
I modified this line in AcronymCategoryPivot.swift.

try builder.removeReference(from: .acronymID, to: \

builder.reference(from: .acronymID, to: \, onDelete: .cascade)

And I got the error below.
Value of type ‘SchemaCreator’ has no member ‘reference’

Appreciated if you could advise what I missing.

Where did you get removeReference from?

Try running swift package update to get the latest version of Fluent

Thanks for the advice and good support.
I can delete acronym data as I want.

removeReference is not from tutorial. It’s my trial code. ^^

1 Like