2017-02-04 132 views
1

我正在開發一個laravel項目,每次更改我的表(添加或刪除列)並運行php artisan migrate:refresh。我得到這個錯誤:Laravel 5:php工匠遷移:刷新

[Symfony\Component\Debug\Exception\FatalErrorException] Can't use method return value in write context

解決方案的嘗試:

  1. 運行composer dump-autoload(失敗)數據庫
  2. DROP TABLE,刪除遷移文件並重新啓動(作品)

先前的遷移文件:

<?php 

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

class CreateCommentsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('comments', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->integer('post_id'); 
      $table->string('body'); 
      $table->timestamps(); 
     }); 
    } 

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

更改遷移文件:

<?php 

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

class CreateCommentsTable extends Migration 
{ 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('comments', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->integer('user_id'); 
      $table->integer('post_id'); 
      $table->string('body'); 
      $table->timestamps(); 
     }); 
    } 

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

我加了USER_ID在改變文件中的up功能

+0

你似乎有問題,在您的遷移碼。你能發佈遷移文件的內容嗎? – ubuntus

+0

完成:)謝謝你的幫助 –

回答

0

試試這個命令,它爲我工作

php artisan migrate:fresh