快递运费:补 deleted_at(模型基类带软删除,页面查询报 Unknown column)

建表迁移同步补 softDeletes,另加一个迁移修复已建好的表;两个迁移都带存在性判断,可重复执行。
This commit is contained in:
qiuxiang 2026-10-08 13:30:20 +08:00
parent 401dfb089a
commit 09ae442b87
2 changed files with 36 additions and 0 deletions

View File

@ -26,6 +26,7 @@ return new class extends Migration
$table->string('transaction_no', 191)->comment('交易单号');
$table->decimal('freight_amount', 18, 4)->default(0)->comment('提供成本运费');
$table->timestamps();
$table->softDeletes();
$table->index(['company_id', 'source'], 'courier_freight_company_source');
$table->index(['company_id', 'transaction_no'], 'courier_freight_company_txn');

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* courier_freight_rows 建表时漏了 deleted_at,而业务模型基类带软删除,
* 导致页面查询报「Unknown column deleted_at」。这里补上;建表迁移也已同步修正,
* 新环境不会重复执行到这里。
*/
return new class extends Migration
{
public function up(): void
{
if (! Schema::hasTable('courier_freight_rows')) {
return;
}
if (! Schema::hasColumn('courier_freight_rows', 'deleted_at')) {
Schema::table('courier_freight_rows', function (Blueprint $table): void {
$table->softDeletes();
});
}
}
public function down(): void
{
if (Schema::hasTable('courier_freight_rows') && Schema::hasColumn('courier_freight_rows', 'deleted_at')) {
Schema::table('courier_freight_rows', function (Blueprint $table): void {
$table->dropSoftDeletes();
});
}
}
};