-3

I am having sql problem. I can not add more than one record line, when I add the first, it works, but when I add the second one it does not work, and so I have to delete one line to be able to add another.

The save mechanism, in theory, works, but only to save a line

"SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or
 update a child row: a foreign key constraint fails (`Gadi`.`printers`,
 CONSTRAINT `printer_id` FOREIGN KEY (`id`) REFERENCES `users` (`id`))
 (SQL: insert into `printers` (`link_printer`, `name_printer`,
`printer_id`, `updated_at`, `created_at`) values (a/printer/api/a?
apikey=e2ddc036-f883-460e-beb6-fc41026d720d&a=stateList&data=, Impre3d,
 1, 2019-06-14 18:08:30, 2019-06-14 18:08:30)) ◀"

In the above error to see clearly that the foreign key is not empty.

2 Answers2

1

I think you have problems with your database structure. Because i can not understand why your printer_id is referencing to users table? And why you have printer_id foreign key in your printers table?

  • `printer_id` is the name of the constraint. The referencing column is `id`, which is probably `AUTO_INCREMENT`. But that also doesn't look reasonable. – Paul Spiegel Jun 14 '19 at 19:48
1

Your database primary key must be showing value as "0" in the first record as you haven't made it as primary key and also auto-increment must have missed. Do below steps to solve the issue. 1. Truncate table 2. Add Primary Key 3. Make primary key as auto-increment