1

I am using laravel and I am trying to do another migration but the table already exists so it is throwing the following error:

[PDOException]
  SQLSTATE[42S01]: Base table or view already 
  exists: 1050 Table 'users' already exists

I've added this line into the migration file:

$table->softDeletes();

This is the full file:

<?php

use Illuminate\Database\Migrations\Migration;

class ConfideSetupUsersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        // Creates the users table
        Schema::create('users', function ($table) {
            $table->increments('id');
            $table->string('firstname');
            $table->string('lastname');
            $table->string('username')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->string('confirmation_code');
            $table->string('remember_token')->nullable();
            $table->softDeletes();
            $table->boolean('confirmed')->default(false);
            $table->timestamps();
        });

        // Creates password reminders table
        Schema::create('password_reminders', function ($table) {
            $table->string('email');
            $table->string('token');
            $table->timestamp('created_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::drop('password_reminders');
        Schema::drop('users');
    }
}

Any ideas what I'm doing wrong?

1 Answer 1

2

You can rollback the migration and then run it again:

php artisan migrate:rollback

And then:

php artisan migrate

Attention in your case this will delete all data from the table since it will drop users and password reminder and then recreate it.

The alternative is to create a new migration:

php artisan migrate:make users_add_soft_deletes

Put this in there:

Schema::table('users', function ($table) {
    $table->softDeletes();
});

And run php artisan migrate to apply the new migration

Sign up to request clarification or add additional context in comments.

2 Comments

ok I see, will the alternative solution allow me to specify where in the table I want this go to?
Yes, if you're using MySQL you can do $table->softDeletes()->after('remember_token');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.