简体   繁体   English

Eloquent 删除 - SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值:

[英]Eloquent Delete - SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value:

I am getting this error:我收到此错误:

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

When trying to delete records through a relationship, using:尝试通过关系删除记录时,使用:

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

The raw query shows as:原始查询显示为:

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

I have searched and searched but cannot find anything specific to this other than it may be something to do with a cast error.我搜索了又搜索,但除了可能与转换错误有关外,找不到任何特定于此的内容。 Maybe something to do with UUID's?也许与UUID有关?

Migrations as follows:迁移如下:

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

I know it's several months old, but since there is no accepted solution I'm posting mine.我知道它已经有几个月的历史了,但是由于没有公认的解决方案,所以我发布了我的解决方案。
I had the exact same error message but in a slightly different context:我收到了完全相同的错误消息,但上下文略有不同:

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

The array contained values that were either strings (like 'ABC1234', like your company_id) or integers.该数组包含的值可以是字符串(如“ABC1234”,如您的 company_id)或整数。

The workaround was when I build this array, I cast everything to string:解决方法是当我构建这个数组时,我将所有内容都转换为字符串:

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

Then no more SQL error, everything works smoothly.然后没有更多的 SQL 错误,一切顺利。

I think you are missing quotes, so that your UUID can be seen as a string type:我认为您缺少引号,因此您的 UUID 可以被视为字符串类型:

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'

The value of company_id is seen as a number/double (in any case not as a string), so you might have forgotten to turn it into a string before you put it into the query. company_id的值被视为数字/双company_id值(在任何情况下都不是字符串),因此您可能忘记在将其放入查询之前将其转换为字符串。

This error message can also occur if the variable you are comparing has no value.如果您比较的变量没有值,也会出现此错误消息。

For example: $id = '' and User::where('id', $id) .例如: $id = ''User::where('id', $id)

I came across this question when searching for solution to same error in my code, i noticed the variable am working on has no value and the error was resolved and code working fine when the variable start getting appropriate values.在我的代码中搜索相同错误的解决方案时,我遇到了这个问题,我注意到正在处理的变量没有值并且错误已解决并且代码在变量开始获得适当的值时工作正常。

I have just run into the exact same issue, when trying to delete Models through an Eloquent scope.在尝试通过 Eloquent 范围删除模型时,我刚刚遇到了完全相同的问题。

This results in the exact same error as abovementioned:这会导致与上述完全相同的错误:

return $query->whereNotIn('remote_status', $this->typeDeletedStatuses)

The solution of type casting was too brittle for my taste, not obvious enough.类型铸造的解决方案对我的口味来说太脆了,不够明显。 So after some trial and error I separated the int and string statuses, and rebuilt the query like so:因此,经过反复试验,我将intstring状态分开,并像这样重建查询:

return $query->whereNotIn('remote_status', $this->typeDeletedStatuses)
            ->orWhereIntegerNotInRaw('remote_status', $this->typeIntDeletedStatuses);

Now the scope works as expected.现在范围按预期工作。

This what I got这是我得到的

SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 's' SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值:'s'

in my case the issue was the type of category columns is Int(11) and in WHERE I used string instead of number then it return that error, I used PDO with prepared and no datetime in the database so this error not related to datetime in my case.在我的情况下,问题是类别列的类型是 Int(11) 并且在 WHERE 我使用字符串而不是数字然后它返回该错误,我使用 PDO 准备好并且数据库中没有日期时间所以这个错误与日期时间无关我的情况。

solved when make WHERE category = 1当 make WHERE category = 1时解决

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LARAVEL:SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值 - LARAVEL : SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value 如何修复'SQLSTATE [22007]:无效的日期时间格式:1292截断了错误的DOUBLE值:'X' - How to fix 'SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 'X'' SQLSTATE[22007]:无效的日期时间格式:1292 日期时间值不正确 - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value Laravel 将时间戳保存为 DateTime - SQLSTATE[22007]:日期时间格式无效:1292 日期时间值不正确: - Timestamp being saved as DateTime by Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: Laravel - SQLSTATE [22007]:无效的日期时间格式:1292 不正确的日期时间值:'1616818311712' - Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1616818311712' SQLSTATE [22007]:日期时间格式无效:1292 日期时间值不正确:“fotostudio”列的“28-01-2022 12:00”。“transaction_details” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '28-01-2022 12:00' for column `fotostudio`.`transaction_details` SQLSTATE [22007]:无效的日期时间格式:1292错误的日期时间值:第1行的“ created_at”列为“ 1970-01-01 00:00:01” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1970-01-01 00:00:01' for column 'created_at' at row 1 “SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:'2018'列'created_at'在第 1 行(SQL:插入到`news` - "SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2018' for column 'created_at' at row 1 (SQL: insert into `news` SQLSTATE [22007]:无效的日期时间格式:1366不正确的整数值 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value SQLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值:问题 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM