dongzhanlian6289 2018-11-08 10:12
浏览 38

Laravel 5.3:完整性约束违规(适用于某些设置)

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:

enter image description here

Staging table:

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭