Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel Migration Fail

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

My Terminal:

INFO Running migrations.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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');

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading