1
votes

Specifications:

Laravel Version: 5.4 PHP Version: 7.0.9 Composer version 1.9.0 XAMP

Description:

In Connection.php line 647:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table users ( id int unsigned not null auto_increment primary key, name varchar(255) not null, email varchar(255) not null, password varchar(255) not null, remember_token varchar(100) null, created_at timestamp null, updated_at tim estamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

In Connection.php line 449:

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

Problem: I have created models and tables of user and Product. It successfully created both migrations and tables but failed to migrate on phpmyadmin sql.

Steps I tried: I have dropped all database and recreated it but still it gives error. I have also used tinker but error is same.

code:

<?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::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');
    }
}
3
do you have two migrations where you have Schema::create('users',...?nakov
I have two migrations, Users and Products. In user i have Schema::create('users', function (Blueprint $table) and In Products i have Schema::create('products', function (Blueprint $table)Khadija Saeed
what packages are you using?lagbox

3 Answers

0
votes

In your users table migration file add this line in up() method

    Schema::dropIfExists('users');

Like this

    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();
     });
    }
1
votes

Try to add the following condition before Schema::create()

if (!Schema::hasTable('users')) {
        Schema::create('users',...)
}
0
votes

Check your migration table if the "User" Table is recorded there, delete it and then do a single migration using this artisan command

php artisan migrate:refresh --path=/database/migrations/fileName.php

Or Do reset the migration using the following and then migrate again

php artisan migrate:reset