2

I created a table like this

CREATE TABLE progettoschemas.categories (
  id DOUBLE NOT NULL,
  name VARCHAR(255) NOT NULL,
  fatherid DOUBLE,
  PRIMARY KEY (id),
  FOREIGN KEY (fatherid) REFERENCES progettoschemas.categories(id) ON UPDATE CASCADE ON DELETE CASCADE)

but when I do this query:

UPDATE categories SET id = 33 WHERE id = 1

I get: Error Code: 1451. Cannot delete or update a parent row: a foreign key constraint fails (categories, CONSTRAINT legame_padrefiglio FOREIGN KEY (fatherid) REFERENCES categorie (id))

What am I doing wrong?

Example of my db

This is a representation of my database

Lorenzo Cutrupi
  • 626
  • 3
  • 13

0 Answers0