Nick385's avatar

Migration

Im doing this lesson: https://laracasts.com/series/laravel-5-fundamentals/episodes/7

and got this error

'''

vagrant@homestead:~/Code/laravel$ php artisan migrate

[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1 duplicate column name: created_at (SQL: create table "articles" ("id" integer not null p
rimary key autoincrement, "title" varchar not null, "body" text not null, "created_at" datetime not null, "updated_at" dat
etime not null, "created_at" datetime not null, "updated_at" datetime not null))

[PDOException]
SQLSTATE[HY000]: General error: 1 duplicate column name: created_at

'''

0 likes
11 replies
Nick385's avatar

Hi @desloc,

vagrant@homestead:~/Code/laravel$ php artisan migrate

The one that gives the error has this code just like the tutorial

'''

use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

class CreateArticlesTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('articles', function(Blueprint $table)
    {
        $table->increments('id');
        $table->string('title');
        $table->text('body');
        $table->timestamps();
        $table->timestamps('published_at');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('articles');
}

} '''

richardbishopme's avatar

Apologies, I mean the actual code for the migration. You can find it in your database/migrations folder in the project. It will start with something like

2014_10_12_100000_create_arrticles_table

richardbishopme's avatar

Thanks! Can you run a

php artisan migrate:rollback

from your command line?

Nick385's avatar

@desloc

vagrant@homestead:~/Code/laravel$ php artisan migrate:rollback Rolled back: 2014_10_12_100000_create_password_resets_table Rolled back: 2014_1012000000_create_users_table

when i rerun it i get the same error and i can then only rollback these 2 the new one doesn't work

richardbishopme's avatar
Level 24

It's fine. Roll it back again and modify the following line:

 $table->timestamps('published_at');

to

 $table->timestamp('published_at');

and then try to migrate again.

Please or to participate in this conversation.