php - Eloquent 删除-SQLSTATE [22007] : Invalid datetime format: 1292 Truncated incorrect DOUBLE value:

标签 php mysql laravel eloquent

我收到这个错误:

SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: '808498e7-a393-42f1-ab23-6ee89eb7040a' 

尝试通过关系删除记录时,使用:

$delivery->stockMovements()->delete();

原始查询显示为:

delete from `stock_movements` where `stock_movements`.`entity_id` = 10000005 and `stock_movements`.`entity_id` is not null and `stock_movements`.`company_id` = 8b11050c-612c-4922-8b34-d04d579e02a9

我搜索了又搜索,但找不到与此相关的任何内容,除了它可能与转换错误有关。也许与 UUID 有关?

迁移如下:

    Schema::create('deliveries', function (Blueprint $table) {
        $table->increments('id');
        $table->uuid('company_id');
        $table->string('delivery_type');
        $table->string('supplier_name');
        $table->string('supplier_ref')->nullable();
        $table->string('merchant_ref')->nullable();
        $table->string('carrier_name')->nullable();
        $table->string('status');
        $table->date('expected_delivery');
        $table->dateTime('completed_at')->nullable();
        $table->timestamps();
    });


    Schema::create('stock_movements', function (Blueprint $table) {
        $table->increments('id');
        $table->uuid('company_id');
        $table->uuid('product_id');
        $table->string('entity_type'); //can be order / delivery
        $table->string('entity_id'); //can be UUID / String / Integer
        $table->string('location_id')->nullable(); // can be warehouse_location / shipment_package / delivery_container
        $table->string('action')->default('');
        $table->integer('qty')->default(0);
        $table->timestamps();
    });

最佳答案

我知道它已经几个月了,但由于没有公认的解决方案,我发布了我的解决方案。
我收到了完全相同的错误消息,但上下文略有不同:

Table::whereIn('fk_id', $arrayOfFkIds)
                ->delete();

该数组包含的值可以是字符串(如“ABC1234”,如您的 company_id)或整数。

解决方法是当我构建这个数组时,我将所有内容都转换为字符串:

$arrayOfFkIds[] = (string)$parsedArray['stuff_id'];

然后没有更多的 SQL 错误,一切顺利。

关于php - Eloquent 删除-SQLSTATE [22007] : Invalid datetime format: 1292 Truncated incorrect DOUBLE value:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53683774/

相关文章:

mysql - InnoDB 表存在于 MySQL 中,但在将数据库复制到新服务器后表示它们不存在

php - 带有选择选项的mysql未知错误

php - odbc_execute 在准备好的语句上失败,然后说它 "failed to fetch error message"

javascript - 从javascript中删除双引号

java - 本地Spring应用如何访问OpenShift上的mysql?

mysql - SQL 查询将字段值复制到同一个表中

php - Laravel Blade View - undefined variable : errors

php - 带有 Laravel 应用程序的自包含 Docker 镜像(无共享卷)

mysql - 嵌套选择查询重构并转换为 Eloquent/查询生成器

php - 在 file_get_contents 之后在 php 中调整图像大小