2
I’m using the ModelFactory
standard of Laravel 5 some time ago, and everything was going ok, but from a few days to here stopped generating data from the library faker
for some tables, although continue normally for others.
When I spin php artisan db:seed -vvv
with the definitions below, the table client
is filled correctly, with all values, and the table email
ends with 100 lines of default or empty values.
Any idea where to start debugging this?
database/Factory/Modelfactory.php (default)
$factory->define(App\Client::class, function ($faker) {
$origins = DB::table('origin')->lists('id');
$methods = DB::table('entry_method')->lists('id');
$image = str_replace('public', '', $faker->image('public/img', '100', '100', 'cats'));
return [
'name' => $faker->firstName,
'middlename' => $faker->lastName,
'lastname' => $faker->lastName,
'birthday' => $faker->date(),
'type' => $faker->randomElement(array('nao-associado','patrimonial','cooperador','coletivo','entidade','emerito','individual')),
'associate_code' => $faker->randomNumber(),
'identification' => str_random(20),
'identification_type' => $faker->randomElement(array('rg','cpf','cnh','passaporte','social-security','outro')),
'language' => $faker->randomElement(array('pt','en')),
'foreigner' => $faker->boolean(),
'image' => $image,
'vip' => $faker->numberBetween(0,1),
'id_origin' => $faker->randomElement($origins),
'id_entry_method' => $faker->randomElement($methods),
];
});
$factory->define(App\Email::class, function ($faker) {
$clients = DB::table('client')->lists('id');
return [
'email' => $faker->companyEmail,
'type' => $faker->randomElement(array('pessoal','comercial')),
'id_client' => $faker->randomElement($clients),
];
});
database/Seeds/Databaseseeder.php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Connection;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
DB::statement('SET FOREIGN_KEY_CHECKS=0');
factory('App\Client', 100)->create();
factory('App\Email', 100)->create();
// create
DB::statement('SET FOREIGN_KEY_CHECKS=1');
Model::reguard();
}
}
app/Email.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Email extends Model
{
public $domains;
public $timestamps = false;
protected $table = 'email';
protected $fillable = ['email', 'type', 'mailchimp_id', 'id_client'];
}
EDIT: Migrations
Schema::create('client', function(Blueprint $table)
{
$table->increments('id');
$table->string('name', 50);
$table->string('middlename', 50)->nullable();
$table->string('lastname', 50);
$table->date('birthday')->nullable();
$table->enum('type', ['nao-associado','patrimonial',
'cooperador','coletivo',
'entidade','emerito',
'individual'])->default('nao-associado');
$table->string('associate_code', 45)->nullable(); // codigo_socio
$table->string('identification'); // documento identidade
$table->enum('identification_type', ['rg','cpf','cnh','passaporte','social-security','outro']); // codigo_socio
$table->enum('language', ['pt','en'])->default('pt');
$table->boolean('foreigner')->default(false);
$table->string('password', 255)->nullable(); // documento identidade
$table->string('image', 255); // foto
$table->boolean('vip')->default(false);
// Foreign keys
$table->integer('id_entry_method')->unsigned();
$table->integer('id_origin')->unsigned();
$table->integer('id_client')->unsigned()->nullable();
$table->foreign('id_entry_method')->references('id')->on('entry_method');
$table->foreign('id_origin')->references('id')->on('origin');
$table->foreign('id_client')->references('id')->on('client');
$table->timestamps();
$table->softDeletes();
});
Schema::create('email', function(Blueprint $table)
{
$table->increments('id');
$table->string('email', 50);
$table->enum('type', ['pessoal','comercial']);
$table->string('mailchimp_id', 100);
$table->integer('id_client')->unsigned();
$table->foreign('id_client')->references('id')->on('client');
});
Could you post the Migration of these two tables? I would like to play here. You may need to add a counter bar before running from the lists:
\DB::
– gmsantos
@gmsantos added Migrations. I haven’t tested yet with
\DB::
but I find it unlikely that this is because the calls to DB work inclient
– Ricardo Moraleida