Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel. Integrity constraint violation: 1452

I just want to ask for a help. i got this error when seeding. can someone help me? thanks alot.

error:

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`cherithportal`.`employee_jobs_statuses`, CONSTRAINT `employee_jobs_statuses_addedby_id_foreign` FOREIGN KEY (`addedBy_id`) REFERENCES `users` (`id`) ON UPDATE CASCADE) (SQL: insert into `employee_jobs_statuses` (`addedBy_id`, `date_added`, `name`) values (30, 2022-11-11 05:42:40, Assigned), (30, 2022-11-11 05:42:40, Interview Scheduled), (30, 2022-11-11 05:42:40, Interview Not Attended), (30, 2022-11-11 05:42:40, Interview Rescheduled), (30, 2022-11-11 05:42:40, Rejected), (30, 2022-11-11 05:42:40, On Hold), (30, 2022-11-11 05:42:40, Selected), (30, 2022-11-11 05:42:40, Offered), (30, 2022-11-11 05:42:40, Did Not Join), (30, 2022-11-11 05:42:40, Joined))

migration:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public function up()
    {
        Schema::create('employee_jobs_statuses', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->dateTime('date_added');
            $table->integer('addedBy_id')->unsigned(); 
            $table->timestamps();
            $table->foreign('addedBy_id')->references('id')->on('users');
        });
    }

Thanks alot. hoping someone can help me.

>Solution :

Hope this helps!

Verify if ‘id’ 30 is present or not in the ‘users’ table.

Here is the value of the ‘addedBy_id’ column of the ’employee_jobs_statuses’ table that you are attempting to insert or update that does not exist in the ‘users’ table.

Do not forget that the values of the "addedBy_id" column of the "employee_jobs_statuses" table depend on the "id" values of the "users" table.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading