2017-02-19 1 views
2

私はLaravel Framework version 5.2.45を実行しており、データベースの移行を移行したいと考えています。Laravel Migrations - 列は既に存在します

2つの移行があります。 (ロールバックする前に)典型的なphp artisan migrateは私が手行う

<?php 

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

class CreateKeywordsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('keywords', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('keyword'); 
      $table->timestamps(); 
      $table->timestamps('published_at'); 

     }); 
    } 

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

:インサイド

root:~/workspace $ php artisan migrate:rollback 
Rolled back: 2014_10_12_100000_create_password_resets_table 
root:~/workspace $ php artisan migrate 


    [Illuminate\Database\QueryException]                             
    SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' (SQL: create table `keywords` (`id` int unsigned not null auto_incr 
    ement primary key, `keyword` varchar(255) not null, `created_at` timestamp null, `updated_at` timestamp null, `created_at` timestamp null, `updated 
    _at` timestamp null) default character set utf8 collate utf8_unicode_ci)                    



    [PDOException]                 
    SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'created_at' 


root:~/workspace $ 

一つは、箱から出てくると、もう一つは、私の新しく作成された移行2017_02_19_172350_create_keywords_tableある標準2014_10_12_100000_create_password_resets_tableですデータベースなしテーブルkeywordsが作成されます。私が間違っているの何

enter image description here

任意の提案ですか?

返信いただきありがとうございます。

+0

** composer dump **コマンドを試してから、** php aristan migration:refresh **を試してみてください – zgabievi

答えて

5

$table->timestamps();は、常にcreated_atフィールドとupdated_atフィールドを追加する関数です。あなたの場合は、これらを2回追加しています。
別のタイムスタンプフィールドを追加する場合は、timestamp()関数を使用する必要があります。

だから、(複数の削除)以下でpublished_atの行を置き換える必要があります。

$table->timestamp('published_at'); 

可能なすべての列タイプのリストがthe documentationで見つけることができます。

関連する問題