Home > Enterprise >  Laravel Migration Fail
Laravel Migration Fail

Time:10-16

I am getting the below mentioned error when I run php artisan migrate

My Terminal:

INFO Running migrations.

2014_10_12_000000_create_users_table .................................................................................................... 3ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table `users` (`id` bigint unsigned not null auto_increment primary key, `name` var
char(191) not null, `email` varchar(191) not null, `email_verified_at` timestamp null, `password` varchar(191) not null, `utype` varchar(191) not null default 'USR' comment 'ADM - Admi
n ucun, USR - normal isdifadeci user ucun', `remember_token` varchar(100) null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at C:\wamp64\www\laravel9ecommerce\vendor\laravel\framework\src\Illuminate\Database\Connection.php:759
    755▕         // If an exception occurs when attempting to run a query, we'll format the error
    756▕         // message to include the bindings with SQL, which will make this exception a
    757▕         // lot more helpful to the developer instead of just the database's errors.
    758▕         catch (Exception $e) {
  ➜ 759▕             throw new QueryException(
    760▕                 $query, $this->prepareBindings($bindings), $e
    761▕             );
    762▕         }
    763▕     }

 /**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->string('utype')->default('USR')->comment('ADM - for admin, USR - for normal user');
        $table->rememberToken();
        $table->timestamps();
    });
}

CodePudding user response:

As the error mentioned, it looks like the users table is already created. You could run:

 php artisan migrate:fresh --seed

However, be careful, this will delete all the tables and run the migration again. If migrate:fresh is not the option for you, you could manually insert a row in migration table with the file name of that users table. example INSERT INTOmigrations (id, migration, batch) VALUES (NULL, '2014_10_12_000000_create_users_table', '1');

  • Related