2016-04-23 120 views
0

我使用Laravel 5.2並希望更改默認用戶表的列。我在CreateUsersTableLaravel默認用戶表

public function up() 
    { 
    Schema::create('users', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('name'); 
     $table->string('email')->unique(); 
     $table->string('password'); 
     $table->rememberToken(); 
     $table->timestamps(); 
    }); 

    Schema::table('users', function ($table) { 
     $table->string('role'); 
     $table->string('info'); 
     $table->string('age'); 
     $table->string('hobies'); 
     $table->string('job'); 
    }); 
    } 

寫道 和我在GIT的bash運行這些命令,但用戶表沒有改變。

php artisan migrate:refresh 
    php artisan migrate 

我該如何解決它?

回答

0

運行php artisan migrate命令後,您應該運行composer dumpauto -o註冊新的遷移,以便它們可以回滾。

試試吧。如果它不會工作,嘗試刪除所有表,包括migrations並運行此命令:

php artisan migrate:install 
+0

謝謝你,但我發現解決這個問題的簡單方法。 – Earthx9

0

你只需要改變一下它的內部Schema::create和刪除您Schema::table

然後,你需要實現參觀down() mehod並添加Schema::drop('users');以便在運行migrate:refresh時放下您的桌子。

您可以閱讀laravel文檔中的'數據庫遷移'以獲取更多詳細信息。

+0

謝謝,但我已經做到了,但沒有奏效。 – Earthx9

0

創建新的遷移文件,做這樣的事情

public function up() { 
    DB::statement('ALTER TABLE user ADD some_field INT');// your query here 
} 

php artisan migrate