I've been using the default% Laravel 5% for some time, and everything was going ok, but for a few days now I've stopped generating data from the ModelFactory
library for some tables, although it's still normal for others.
When you start faker
with the definitions below, the php artisan db:seed -vvv
table is filled correctly, with all values, and the client
table ends with 100 lines of default or empty values.
Any ideas on where to begin 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');
});