php - 雄辩的删除 - 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();
});
解决方案
我知道它已经有几个月的历史了,但是由于没有公认的解决方案,我发布了我的解决方案。
我收到了完全相同的错误消息,但上下文略有不同:
Table::whereIn('fk_id', $arrayOfFkIds)
->delete();
该数组包含的值可以是字符串(如“ABC1234”,如您的 company_id)或整数。
解决方法是当我构建这个数组时,我将所有内容都转换为字符串:
$arrayOfFkIds[] = (string)$parsedArray['stuff_id'];
然后没有更多的SQL错误,一切顺利。
推荐阅读
- laravel - Laravel 搜索栏
- amazon-web-services - AWS 代码管道,dockerfile 无法访问环境变量 CODEBUILD_SRC_DIR 和 CODEBUILD_SRC_DIR_SecondarySource
- mongodb - 使用 $inc 更新多个数组元素
- javascript - Django webpack loader:如何引用webpack编译的静态图片
- visual-studio - 我无法在 Visual Studio 2019 xamarin 表单中创建模拟器
- c - 从给定范围内查找缺失值
- mysql - 使用 mysql 命令将行插入到使用 Terraform 的 db 表中
- aws-lambda - localstack 的 Lambda 函数中 DynamoDB 的端点 URL
- amazon-athena - 使用 information_schema 目录确定 AWS Athena 中的表创建日期?
- android - 延迟后显示Android动画