Cannot delete or update a parent row #1573
Answered
by
RomainLanz
LeadcodeDev
asked this question in
Help
-
Hi ! I would like to delete one service but when I use delete method on my controller, I have this error
Following my service model : export default class Service extends BaseModel {
@column({ isPrimary: true })
public id: number
@column()
public label: string
@column()
public description: string
@column()
public isVisible: boolean
@hasMany(() => Detail)
public details: HasMany<typeof Detail>
@hasOne(() => Picture)
public picture: HasOne<typeof Picture>
} How can I delete my item while also deleting the assigned relationships ? |
Beta Was this translation helpful? Give feedback.
Answered by
RomainLanz
Sep 8, 2020
Replies: 1 comment 1 reply
-
Hey @LeadcodeDev! 👋 You need to properly create your table. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
LeadcodeDev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @LeadcodeDev! 👋
You need to properly create your table.
When creating the foreign key in your migration, you should specify using the
onDelete
hook what you want to do. For your case, it should becascade
.