2
votes

Whenever I make new migrations and trying to migrate it the results I get is this. Even if I try to migrate:refresh and so on. What do you think the problem here? I have also checked my .env file. Thank you!

[Illuminate\Database\QueryException] 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)

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

2

2 Answers

0
votes

The problem is that you're trying to create a table that already exists in the database,

Either delete the users table from the database before running php artisan migrate:refresh

Or if you have made another migration to add a new column into the users table then you need to have

Schema::table('users', function (Blueprint $table)

Instead of

Schema::create('users', function (Blueprint $table)

It's important to not that Schema::create will create the table, and Schema::table is what you'd use when modifying an existing table.

0
votes

Use !Schema::hasTable('users'), it will check whether a table already exists in the database or not.

If you don't want to drop already exist tables then it is a good idea.

if (!Schema::hasTable('users')) {
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}