[英]ErrorException array to string conversion on migrate --seed
I'm trying to set up my very first laravel project however when I try to have artisan to seed the database with faker it throws 我正在尝试建立我的第一个laravel项目,但是当我尝试让技术人员使用伪造者为数据库播种时,它会抛出
[errorException] array to string conversion
[errorException]数组到字符串的转换
I'm just working with the stock users migration file and using the command php artisan migrate --seed 我正在使用股票用户迁移文件,并使用命令php artisan migration --seed
Any guidance would be greatly appreciated 任何指导将不胜感激
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->string('role', array('user', 'admin', 'superuser'));
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
and this UserTableSeeder that artisan generated for me 和这个工匠为我生成的UserTableSeeder
use Illuminate\Database\Seeder;
class UserTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(App\User::class, 49)->create();
factory(App\User::class)->create([
'name' => 'admin',
'role' => 'admin',
]);
}
}
this is my Modelfactory.php 这是我的Modelfactory.php
$factory->define(App\User::class, function ($faker) {
return [
'name' => $faker->name,
'email' => $faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
'role' => $faker->word->randomElement(array('user','superuser')),
];
});
$table->string('role', array('user', 'admin', 'superuser'));
You are selecting a type of string and then providing an array. 您正在选择一种字符串类型,然后提供一个数组。
This is exactly what your error is talking about. 这正是您的错误所谈论的。
Your error is because of this line 您的错误是因为此行
$table->string('role', array('user', 'admin', 'superuser'));
change string to enum ; 将字符串更改为枚举 ; ex:
例如:
$table->enum('role', array('user', 'admin', 'superuser'));
this will execute. 这将执行。
You say string but provide an array in this line: 您说字符串,但在此行中提供一个数组:
$table->string('role', array('user', 'admin', 'superuser'));
You should use : 您应该使用:
$table->enum('role', ['user', 'admin', 'superuser']);
For reference see here: 供参考,请参见此处:
https://laravel.com/docs/5.8/migrations#creating-columns https://laravel.com/docs/5.8/migrations#creating-columns
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.