Laravel 5.5 Error Base Table or View Already Exists: 1050 Table 'Users' Already Exists

Laravel 5.5 Error Base table or view already exists: 1050 Table 'users' already exists

I Solved My Problem Myself
by Changing My create_users_table.php

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::dropIfExists('users');
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'payments' already exists (SQL: create table `payments`

If you want to recreate the table, run php migrate:rollback first to delete the existing one. This command will run the down() method in the migration.

Then run php migrate to create the table again.

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

Try like this

   <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserTable extends Migration
{

public function up()
{
Schema::dropIfExists('users');
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->integer('role_id')->unsigned();
$table->string('name');
$table->string('email',50)->unique();
$table->string('username');
$table->string('password');
$table->boolean('active');
$table->rememberToken();
$table->timestamps();

});
}

public function down()
{
Schema::dropIfExists('users');
}
}

Laravel Migration table already exists, but I want to add new not the older

You need to run

php artisan migrate:rollback

if that also fails just go in and drop all the tables which you may have to do as it seems your migration table is messed up or your user table when you ran a previous rollback did not drop the table.

EDIT:

The reason this happens is that you ran a rollback previously and it had some error in the code or did not drop the table. This still however messes up the laravel migration table and as far as it's concerned you now have no record of pushing the user table up. The user table does already exist however and this error is throw.

Even if i migrate:fresh it shows me that the table already exists.. why?

First drop roles table using this code Schema::dropIfExists('roles'); then create.

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolesTable extends Migration
{
public function up()
{
Schema::dropIfExists('roles'); //added
Schema::create('roles', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->tinyInteger('status');
});
}

public function down()
{
Schema::dropIfExists('roles');
}
}


Related Topics



Leave a reply



Submit