0

I have tables like this:

Notes
ID | NAME | CATEGORY
1  | test | 1
2  | test2| 2

Notes Category
ID | NAME | COUNT
1  | tCat | 1
2  | tCat2| 1

And I have foreign key CATEGORY <-> Notes Category.ID

I try update first record in Notes and set the null as CATEGORY because I want to have notes without category and I get errror:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

JRulle
  • 7,448
  • 6
  • 39
  • 61
Krzyś Iu
  • 35
  • 8

2 Answers2

0
ALTER TABLE `Notes` DROP FOREIGN KEY Notes_ibfk_1;
UPDATE `Notes` SET CATEGORY = NULL WHERE ID = 1;
ALTER TABLE `Notes` ADD FOREIGN KEY -- http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html
danielsos2
  • 11
  • 3
0

Try specifically declaring CATEGORY as INT NULL in the NOTES table

scubasteve623
  • 637
  • 4
  • 7