小编mus*_*lla的帖子

Laravel 5:PHP Artisan迁移:刷新

我正在做一个laravel项目,每次更改表(添加或删除列)并运行php artisan migrate:refresh。我收到此错误:

[Symfony \ Component \ Debug \ Exception \ FatalErrorException]无法在写上下文中使用方法返回值

解决方案尝试:

  1. 运行composer dump-autoload(失败)
  2. 将表拖放到数据库中,删除迁移文件,然后再次重新启动(有效)

先前的迁移文件:

<?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');
    }
}
Run Code Online (Sandbox Code Playgroud)

更改的迁移文件:

    <?php

use Illuminate\Support\Facades\Schema;
use …
Run Code Online (Sandbox Code Playgroud)

php laravel-5 laravel-5.5

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

laravel-5 ×1

laravel-5.5 ×1

php ×1