Home > Enterprise >  I been suffering a problem when I run php artisan migrate command
I been suffering a problem when I run php artisan migrate command

Time:06-30

When I run php artisan migrate command then I see this error. I have an idea for this error is that I deleted the product migration from the migrations table. What can I do to migrate the product table?

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'products' already exists (SQL: create table products(idbigint unsigned not null auto_increm ent primary key, category_id int not null, subcategory_id int not null, product_name ...) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at F:\xampp\htdocs\suzayetstore\vendor\laravel\framework\src\Illuminate\Datahase\Connection.php:742

F:\xampp\htdocs\suzayetstore\vendor\laravel\framework\src\Illuminate\Database\Connection.php:527 PDOException::("SQLSTATE[42501]: Base table or view already exists: 1050 Table 'products' already exists")

CodePudding user response:

This issue happens because you already have a table in your database and you are trying to migrate the same table without droping(deleting) it. You have 2 options which I have explained below,

If you already dont have any datas in your database tables. Then you can use,

php artisan migrate:fresh

So that all the tables will be deleted and recreated again.

If you need already have datas in any of your table in your database. And you need the datas. You just need to delete the table from database. For that use the query below,

drop table tablename;

And then, run the below command,

php artisan migrate
  • Related