Codeigniter 4 Seeder 出错,"Array to string conversion"

Codeigniter 4 Seeder gives an error, "Array to string conversion"

当我添加 dh_setting_context' => 'user1' 时,我收到 Array to string conversion 错误,但是,当我从播种器中删除该行时,它起作用并且 table 被正确填充。为什么 dh_setting_context' => 'user1' 生成器会出错,请问如何解决?

这是我的种子文件

namespace App\Database\Seeds;
use CodeIgniter\Database\Seeder;
use \CodeIgniter\I18n\Time;

class DhSettingSeeder extends Seeder
{

public function run()
{
    $data = [
        
        // app - General App Settings
        [
            'dh_setting_key'            => 'app.dh_company_name' ,
            'dh_setting_value'          => 'ABC Big Co., Ltd',
            'dh_setting_created_at'     => Time::now(),
            'dh_setting_updated_at'     => Time::now()
        ],
        
        [
            'dh_setting_key'            => 'app.dh_company_address_line_1' ,
            'dh_setting_value'          => '123 Long Street',
            'dh_setting_created_at'     => Time::now(),
            'dh_setting_updated_at'     => Time::now()
        ],
        
        
        // email - general settings for email
        [
            'dh_setting_key'            => 'email.fromEmail' ,
            'dh_setting_value'          => 'example@yahoo.com',
            'dh_setting_created_at'     => Time::now(),
            'dh_setting_updated_at'     => Time::now()
        ],
        [
            'dh_setting_key'            => 'email.SMTPHost' ,
            'dh_setting_value'          => 'smtp.mail.yahoo.com',
            'dh_setting_created_at'     => Time::now(),
            'dh_setting_updated_at'     => Time::now()
        ],
        // add some user settings for admin user (user id = 1)
        [
            'dh_setting_key'            => 'user.timezone' ,
            'dh_setting_value'          => 'gmt',
            'dh_setting_context'        => 'user1',
            'dh_setting_created_at'     => Time::now(),
            'dh_setting_updated_at'     => Time::now()
        ]
    ];
    $this->db->table('dh_setting')->insertBatch($data);
}
}

这是我的 table

的结构

并非 $data 中的所有条目都具有相同的键。

CodeIgniter 从第一个条目('dh_setting_key''dh_setting_value''dh_setting_created_at''dh_setting_updated_at')中获取密钥,并使用这些密钥检查 $data.

如果条目的键相同,它会创建一个包含条目值的字符串。

如果一个条目的键不同,它会创建一个空数组。

对于 INSERT 查询,CodeIgniter 然后尝试将值字符串与空数组连接起来,这是不允许的并给出错误。

要修复,请将 'dh_setting_context' => null, 添加到其他条目。