2017-02-04 148 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