编程语言
首页 > 编程语言> > Laravel 5:PHP Artisan迁移:刷新

Laravel 5:PHP Artisan迁移:刷新

作者:互联网

我在laravel项目上工作,每次更改表(添加或删除列)并运行php artisan migrate:refresh时.我收到此错误:

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

解决方案尝试:

>运行composer dump-autoload(失败)
>在数据库中删除表,删除迁移文件,然后再次重新启动(有效)

先前的迁移文件:

<?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');
    }
}

我在up函数的更改文件中添加了user_id

解决方法:

试试这个命令对我有用

php artisan migrate:fresh

标签:laravel-5-5,laravel-5,php
来源: https://codeday.me/bug/20191111/2022128.html