首页 > 解决方案 > 雄辩的删除 - SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值:

问题描述

我收到此错误:

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();
    });

标签: phpmysqllaraveleloquent

解决方案


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

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

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

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

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

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


推荐阅读