简体   繁体   English

迁移--seed时将ErrorException数组转换为字符串

[英]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.

相关问题 ErrorException:PHP中的数组到字符串的转换 - ErrorException : Array to string conversion in PHP ErrorException 数组到 Controller 文件中的字符串转换 - ErrorException Array to string conversion in Controller file ErrorException [注意]:数组到字符串转换PHP表单 - ErrorException [Notice]:Array to string conversion PHP Form 提交表单时出现“ErrorException 数组到字符串的转换” - "ErrorException Array to string conversion" when submitting a form 带有转发器字段的 Laravel 表单提交中的 ErrorException 数组到字符串转换 - ErrorException Array to string conversion in Laravel form submission with repeater fields ErrorException 数组到字符串的转换 Laravel - 将 JSON 导入到 MySQL - ErrorException Array to string conversion Laravel - Importing JSON to MySQL Laravel 中的 ErrorException (E_NOTICE) 数组到字符串的转换 - ErrorException (E_NOTICE) Array to string conversion in Laravel 使用Laravel和Lang :: get()进行代码接收“ ErrorException数组到字符串的转换” - Codeception “ErrorException array to string conversion” with Laravel and Lang::get() PHP公告– yii \\ base \\ ErrorException(数组到字符串的转换)Yii - PHP Notice – yii\base\ErrorException (Array to string conversion) Yii 在 laravel 中上传图像时数组到字符串转换 ErrorException - Array to string conversion ErrorException while uploading image in laravel 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM