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?
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.
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.
I think you are missing quotes, so that your UUID can be seen as a string type:
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.
This error message can also occur if the variable you are comparing has no value.
For example: $id = ''
and 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.
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:
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'
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.
solved when make WHERE category = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.