Home > Blockchain >  table 'users' already exists laravel when migrate laravel
table 'users' already exists laravel when migrate laravel

Time:02-15

I'm having a problem when I run the migrate command, and I get the following message Base table or view already exists: 1050 Table 'users' already exists

CodePudding user response:

In the Migration part of the up function, type this line at the beginning if(Schema::hasTable('users')) return;

CodePudding user response:

This means that the migration process has encountered a pre-existing table with the same name in the database you're trying to migrate in. In this case, you can either delete all tables in your database manually (Not recommended), or you can migrate with the fresh command so that it deletes all tables in your migration automatically to prevent issues with duplicate tables or constraints.

In your terminal, simply run:

php artisan migrate:fresh

If that doesn't solve it, this might mean you have two migrations with the name "users", so go over all of your migrations and be sure no two classes contain a table creation line that looks like this:

Schema::create('users'...)
  • Related