Home > Software engineering >  Laravel. Integrity constraint violation: 1452
Laravel. Integrity constraint violation: 1452

Time:11-11

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:

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.

CodePudding user response:

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.

  • Related