mardi 2 août 2016

Need some help to slove QueryException by Database Seeding

i have some Problems with Database Seeding. At the last object the Relation is not working. It says that the unsigned key with the id from the previous is empty.

I dont now if i do something from with the complex Code in the DatabaseSeeder or something in the other parts. If its necessary to now the other Code part than i will post it.

Error:

[Illuminate\Database\QueryException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'record_id' in 'field list' (SQL: insert into `values` (`val
  ue`, `record_id`, `updated_at`, `created_at`) values (VIII, , 2016-08-02 11:16:34, 2016-08-02 11:16:34))



[PDOException]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'record_id' in 'field list'

Seed code:

factory(App\User::class, 50)->create()->each(function ($u) {
        $u->logger()->save(factory(App\Logger::class, 10)->make()->each(function ($l) {
            $l->package()->save(factory(App\Package::class, 100)->make()->each(function ($p) {
                $p->records()->save(factory(App\Record::class, 1000)->make()->each(function ($r) {
                    for ($x = 0; $x <= 10; $x++) {
                        $r->values()->save(factory(App\Value::class)->make());
                    }
                }));
            }));
        }));
    });

Factory:

<?php

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/

$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->safeEmail,
        'password' => bcrypt(str_random(10)),
        'remember_token' => str_random(10),
        'ftp_folder' => str_random(10),
    ];
});

$factory->define(App\Logger::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'description' => $faker->word,
    ];
});

$factory->define(App\Package::class, function (Faker\Generator $faker) {
    return [
        'station_id' => $faker->century,
        'signal_quality' => $faker->century,
        'battery' => $faker->century,
        'checksum' => $faker->century,
    ];
});

$factory->define(App\Record::class, function (Faker\Generator $faker) {
    return [
        'timestamp' => $faker->dateTimeThisYear,
    ];
});

$factory->define(App\Value::class, function (Faker\Generator $faker) {
    return [
        'value' => $faker->century,
    ];
});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire