I have created some test model classes, which have corresponding migrations and seeders. It all works very well, except that the updated_at and created_at timestamps have a default value of 0000-00-00 00:00:00. I could perhaps understand the logic of having the updated_at column having this empty default value, but surely the whole point of the created_at column is that it gets a CURRENT_TIMESTAMP value when a record is created?
Someone asked about this a year ago on stack overflow: http://stackoverflow.com/questions/18067614/how-can-i-set-the-default-value-of-a-timestamp-column-to-current-timestamp-on-u/20822267#20822267
However, the solution listed is to set the default value of both columns to CURRENT_TIMESTAMP at MySQL server-level. However, the version of MySQL I have to use is not cutting edge, so it won't let me have more than one CURRENT_TIMESTAMP column.
Is there another way to fix this? Am I doing something wrong?
/*Migration*/
Schema::create('cats', function($t) {
$t->increments('id');
$t->timestamps();
/*etc...*/
});
/*Seeder*/
class CatsTableSeeder extends Seeder {
public function run()
{
DB::table('cats')->insert([
['name' => 'Elvis', 'breed_id' => 1, 'user_id' => 4, 'date_of_birth' => '2004-08-04'],
/*...etc...*/
});
}
}
/*Model*/
class Cat extends Eloquent {
protected $table = 'cats';
protected $fillable = ['name', 'date_of_birth', 'breed_id', 'is_shared'];
public $timestamps = true;
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community