简体   繁体   中英

Laravel error - QueryException in Connection.php line 729:

Receiving this error:

QueryException in Connection.php line 729:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`projects`, CONSTRAINT `projects_am_id_foreign` FOREIGN KEY (`am_id`) REFERENCES `employees` (`id`)) (SQL: insert into `projects` (`company`, `stage`, `status`, `jira`, `notes`, `updated_at`, `created_at`) values (Test, Waiting for Launch, In Progress, https://www.test.com, Testing, 2017-03-02 14:46:47, 2017-03-02 14:46:47))

Projects Table id company am_id etc etc

Employees Table id name department

I have the values in the other table so not sure why it can't reference them. Any ideas?

When you save your project Model, make sure the am_id is filled in.

Now you're trying to save a Project model without the am_id filled in => foreign key error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM