Laravel/faker 使用无效的列名

Laravel/faker using invalid column names

我正在 运行 宁一个 Laravel 5.4 三天前才创建的项目。

我的ModelFactory.php里有这个:

$factory->define(\App\Models\Definition::class, function (Faker\Generator $faker) {
$tag = "tag";
$category = "cat";

return [
    'name' => $faker->words,
    'description' => $faker->realText,
    'tags' => $tag,
    'price' => $faker->numberBetween(500, 50000),
    'category' => $category
];
});

在我的 DatabaseSeeder.phprun():

DB::table('definitions')->truncate();
factory(Definition::class, 200)->create();

但是当我 运行 db:seed 时,我不断得到:

SQLSTATE[HY000]: General error: 1 table definitions has no column named 0 (SQL: insert into "definitions" ("0", "1", "2") select quia as "0", No, there were no arches left, and all dripping wet, cross, and uncomfortable. The first thing I've got totag' (Alice had no reason to be ashamed of yourself for asking such a rule at processions;. as "1", 1302 as "2" union all select cat as "0", 2017-03-17 10:51:53 as "1", 2017-03-17 10:51:53 as "2" uni on all select ? as "0", ? as "1", ? as "2" union all select ? as "0", ? as "1", ? as "2" union all select ? as "0", ? as "1", ? as "2" union all select ? as "0", ? as "1", ? as "2" union all select ? as "0", ? as "1", ? as "2")

我的 table 架构:

Schema::create('definitions', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('description')->nullable();
        $table->integer('price');
        $table->json("tags");
        $table->string('category');
        $table->unsignedInteger('x_id')->nullable(); 
        $table->nullableTimestamps();

我的定义 class 中有 $guarded = [];。我在想这可能是一些伪造的错误,因为我没有想法。

 'description' => $faker->realText

这应该是一个函数。

 'description' => $faker->realText()

还有

 'name' => $faker->words

应该是一个函数,但它 returns 是一个数组,而不是字符串。 你可以使用

 'name' => $faker->name()

 'name' => $faker->sentence(3)

如果你只想要一个 3 个单词的句子。