0

my table

I have a table like in the photo. The foreign key looks like this:

ADD CONSTRAINT `user_set` FOREIGN KEY (`id_usr`) REFERENCES `users` (`id_usr`) ON DELETE CASCADE ON UPDATE CASCADE;

Then, there is a trigger too.

CREATE TRIGGER `add_usr_set` AFTER INSERT ON `users` FOR EACH ROW BEGIN INSERT INTO usr_set VALUES(NEW.id_usr, '1', '1', NULL); END

I can't insert data to users table. I get this error : Column count doesn't match value count at row 1

What's wrong?

For addition, my 'users.usr_img' field is default NULL. So, i think every field have their value

  • Your are only supplying 4 values for the insert into `usr_set` but it has 5 columns. If you only want to insert 4 values, you must specify which 4 columns e.g. `INSERT INTO usr_set (id_usr, see_prf, see_img, dark) VALUES(NEW.id_usr, '1', '1', NULL)` or specify the value for the 5th column e.g. `INSERT INTO usr_set VALUES(NULL, NEW.id_usr, '1', '1', NULL)` (I've assumed it's the `id` column you're not supplying a value for) – Nick May 09 '21 at 00:43
  • My `usr_set.id` and `users.id_usr` is auto increment. And `users.usr_img` is default null. Please tell me which id field is not supplied – Libr_Affandi May 09 '21 at 03:51
  • You are not supplying a value for `usr_set.id` in your insert. Using either of the solutions I proposed in my comment should solve your problem. – Nick May 09 '21 at 03:54
  • Thanks. You solve it. I just changed the trigger to ```INSERT INTO usr_set (`id_usr`) VALUES(NEW.id_usr);``` – Libr_Affandi May 09 '21 at 22:54

0 Answers0