Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Migration and seeding error

Tags:

laravel

I am just starting to use the Laravel framework and its command prompt. I'm having trouble with the migration and seeding features, however.

I am developing on a WAMP server on a Windows 7 64-bit OS.

The database name is 'laravel', with the following two tables:

  1. Migrations
  2. users

The users table contains the following columns:

  • id
  • name
  • email
  • username
  • password

I used the command line to generate a migration stored in app\database\migrations\2014_06_24_221654_test.php. I also created the migration and batch fields in the migration table.

I then want to seed an email to that table, so I used DatabaseSeeder.php in the database\seeds folder.

<?php class DatabaseSeeder extends Seeder {

public function run()
{
    $this->call('UserTableSeeder');

    $this->command->info('User table seeded!');
}

}

class UserTableSeeder extends Seeder {

protected $fillable = array('email');

public function run()
{


    User::create(array('email' => '[email protected]'));
}

}

?>

I then used the following command to seed the database

php artisan db:seed

However, I got the following exception:

 [Illuminate\Database\QueryException]

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field
 list' (SQL: insert into `users` (`email`, `updated_at`, `created_at`) values (ji
 [email protected], 2014-06-25 00:23:48, 2014-06-25 00:23:48))

How can I solve this? Do I need a model?

like image 284
Jishad Avatar asked Dec 25 '22 07:12

Jishad


1 Answers

Thats because your User model use timestamps fields.

Check your User model file.

You could find something like this $this->timestamps = true in your constructor. Change it to false and try again. If you don't find something like this, then add this attribute to the class:

public $timestamps = false; 

I hope it works fine for you.

like image 128
fmgonzalez Avatar answered Feb 15 '23 01:02

fmgonzalez