Friday, March 17, 2017

Laravel/faker using invalid column names

I'm running a Laravel 5.4 project created just three days ago.

I have this in my 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
];
});

And in my DatabaseSeeder.php's run():

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

But when I run db:seed, i keep getting:

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")

My table schema:

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();

I have $guarded = []; in my Definition class. I'm thinking maybe this is some faker bug, because I'm out of ideas.



via shalvah

Advertisement