laravel - Laravel 播种机卡住并返回ErrorException 数组哟字符串转换
问题描述
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('name', 40)->unique();
$table->json('value');
$table->timestamps();
});
//seeder to insert FTP settings
DB::table("settings")->insert([
'name' => 'FTP_SETTINGS',
'value' => ['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21']
]);
}
之后我正在使用播种机进行此迁移(我也将其放入播种机部分,但有同样的问题),但我得到了 ErrorException 数组到字符串的转换。可能是具有价值的东西,但我无法理解我做错了什么......非常感谢您的帮助。
解决方案
您正在尝试将数组值插入到 json 文件中。
Try instead:
DB::table("settings")->insert([
'name' => 'FTP_SETTINGS',
'value' => json_encode(['host' => '192.168.5.190', 'username'=> 'Alessandro', 'password' => 'Alessandro', 'port' => '21'])
]);
推荐阅读
- angular - 需要一个 SOAP 服务器才能在 Angular 中运行
- opengl - 如何使用 OpenGL Shader 模拟“Glow Dodge”混合?
- python - 在 python 中导出具有“类型”和“大小”列的字典
- powerbi - Power BI 中的 DAX - 如何添加度量来计算百分比
- django - 在没有复制粘贴到控制台的情况下对 Django 授权进行 Spotipy
- google-apps-script - 谷歌表 - 脚本 - 与内容约会单元格
- python - 如何将变量保存到文本文件并稍后检索?
- sql - 将 case 语句放入 max() 函数和 where 语句中
- node.js - 使用流进行 Mongoose 查询真的值得吗?
- swift - 服务器回调时按下 SwiftUI 按钮并转到下一个屏幕(下一个视图)