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
Using Ajax to Pass Variable to PHP and Retrieve Those Using Ajax Again
Having Two Different Sessions in Same Domain
How Come Checkbox State Is Not Always Passed Along to PHP Script
Warning: Array_Combine(): Both Parameters Should Have an Equal Number of Elements
PHP - Add Link to a Url in a String
File_Get_HTML Displays Fatal Error Call to Undefined Function
Mysqli Prepared Statement Column with Variable
Image - Upload Not Responding, No Access to $_Files
Session Timeouts in PHP: Best Practices
Wordpress: Loading Multiple Scripts with Enqueue
Detecting a Url Using Preg_Match? Without Http:// in the String
PHP Recursively Unset Array Keys If Match
Fix Incorrectly Displayed Encoding on an HTML Document with PHP
$_Post Is Empty After Form Submit
Laravel Livewire Component Not Refreshing/Reloading Automatically After Refreshing It
Is There a Built-In Function or Plugin to Handle Date Formatting in JavaScript