运行播种机时,我在Laravel 9上遇到错误,它显示为Array to string conversion
我在这个DataMaster
表之前有一个相同的seeder类型json,它工作正常。但是当我运行DataMasterSeeder时,它不工作
我的播种机:
<?php
namespace Database\Seeders;
use App\Models\DataMaster;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DataMasterSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//SDU
DataMaster::create(['formId' => 1, 'userId' => 1, 'kecamatanId' => 1, 'desaId' => null, 'fieldDatas' => [['id' => '1', 'name' => 'jumlah', 'title' => 'Jumlah', 'value' => '4605']], 'level' => 'kecamatan']);
}
}
我的DataMaster迁移:
public function up()
{
Schema::create('data_masters', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('formId');
$table->unsignedBigInteger('userId');
$table->unsignedBigInteger('kecamatanId')->nullable();
$table->unsignedBigInteger('desaId')->nullable();
$table->json('fieldDatas');
$table->enum('level', ['kecamatan', 'desa']);
$table->timestamps();
$table->foreign("formId")->references("id")->on("forms")->onDelete('cascade');
$table->foreign("userId")->references("id")->on("users")->onDelete('cascade');
$table->foreign("kecamatanId")->references("id")->on("kecamatans")->onDelete('cascade');
$table->foreign("desaId")->references("id")->on("desas")->onDelete('cascade');
});
}
我有另一个种子,如fieldDatas json字段在这个DataMaster种子,我运行它成功之前,运行DataMaster种子。
1条答案
按热度按时间huwehgph1#
您应该在插入
fieldDatas
字段之前对其进行编码