Skip to content
Advertisement

Laravel 5: php artisan migrate:refresh

I am working on a laravel project and each time I change my table (add or remove column) and run php artisan migrate:refresh. I get this error:

[SymfonyComponentDebugExceptionFatalErrorException] Can’t use method return value in write context

Solution tried:

  1. run composer dump-autoload (Fails)
  2. Drop table in database, delete the migration file and restart again (works)

Previous migration file:

<?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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

Changed migration file:

    <?php

use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;

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

I added the user_id in the change file in the up function

Advertisement

Answer

Try this command it works for me

php artisan migrate:fresh

However, be careful! This command will drop all data from your DB:

Note: The migrate:fresh command will drop all tables from the database and then execute the migrate command.

as per Laravel docs.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement