Problem updating Fk

I’m having trouble updating Fk
I don’t know how I can solve this problem

error: Cannot add or update a child row: a foreign key constraint fails (spp.linhas, CONSTRAINT linhas_encarregado_id_foreign FOREIGN KEY (encarregado_id) REFERENCES encarregados (id) ON DELETE SET NULL ON UPDATE CASCADE)

method update:

` async update ({ request, params }) {
    const linha = await Linha.findOrFail(
    const data = request.all()


    return linha


	"nome": "Linha 556",
	"encarregado_id": "2",
	"cidade_inicio": "Santa Luzia Ma",
	"cidade_fim": "São Mateus",
	"qtd_tratores": "6",
	"qtd_tratoristas": "8",
	"qtd_trabalhadores_manual": "18"
1 Like

As the error message says, you have to set UPDATE (onUpdate() )operations on CASCADE for that foreign key.

You can do that in a migration file:


ok… thank you