I'm trying to accomplish a self-reference setup, so an user can add an object of identical type to it's relationel table.
It works perfectly on my local machine and on my staging environment, but on production it keeps returning an error. Local and staging runs php 7 and production runs php 5; but I dont think the error is related to this?
I really can't figure out why - so I'd really appreciate any help!
I've marked the specific line with (Error) that triggers the error.
Controller: BasicCalculationController.php
$bcItem = BasicCalculation::with( 'unit' )->find( $id );
Error: $basicCalculation->basicCalculation()->save( $bcItem, [
'organization_id' => $org->id,
'quantity' => $quantity
] );
Model BasicCalculation.php:
public function basicCalculation() {
return $this->belongsToMany( 'App\Models\BasicCalculation', 'calculations_basic_calculations', 'calculation_id', 'basic_calculation_id' )->withPivot( 'organization_id', 'quantity' )->withTimestamps();
}
Works perfectly on local + staging. Dosen't work on production.
The error that is returned from MySQL is:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`calcueasy`.`calculations_basic_calculations`, CONSTRAINT `calculations_basic_calculations_calculation_id_foreign` FOREIGN KEY (`calculation_id`) REFERENCES `calculations` (`id`)) (SQL: insert into `calculations_basic_calculations` (`basic_calculation_id`, `calculation_id`, `created_at`, `organization_id`, `quantity`, `updated_at`) values (560, 38, 2018-11-08 10:06:13, 1, 22.00000, 2018-11-08 10:06:13)) in C:\laragon\www\CalcuEasy\vendor\laravel\framework\src\Illuminate\Database\Connection.php:770
Update:
Production table:
Staging table: