Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while run migrate command in laravel 8

I'm using Laravel Cashier package.

I've added below line AppServiceProvider.php > boot method

 Cashier::ignoreMigrations();

I've create my own migration i.e: create_subscriptions_table and create_subscription_items_table

When I run php artisan migrate command then getting below error:

   Migrating: 2019_05_03_000002_create_subscriptions_table

   Illuminate\Database\QueryException 

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'subscriptions' already exists (SQL: create table `subscriptions` (`id` bigint unsigned not null auto_increment primary key, `user_id` bigint unsigned not null, `name` varchar(191) not null, `stripe_id` varchar(191) not null, `stripe_status` varchar(191) not null, `stripe_plan` varchar(191) null, `quantity` int null, `trial_ends_at` timestamp null, `ends_at` timestamp null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') 

I get this error because migration 2019_05_03_000002_create_subscriptions_table is in vendor folder.

I want run my own migration not from vendor so is there any solution to fix this issue ?

like image 866
Milan Avatar asked Jun 11 '21 09:06

Milan


People also ask

How do I run a migration file in Laravel?

IF you want to re-migrate all the database, you can simply do: php artisan migrate:refresh . IF you want to make sure your database to be clean with your latest changes, you can drop your entire database tables and do php artisan migrate again. Also, you can try php artisan migrate --seed if you have any seeder.

How do I migrate in Laravel?

To create a new migration, you can run the make:migration Artisan command and that will bootstrap a new class on your Laravel application, in the database/migrations folder. This class will contain a default boilerplate code.

What is migrate command in Laravel?

Roll Back & Migrate Using A Single Command The migrate:refresh command will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database: php artisan migrate:refresh. # Refresh the database and run all database seeds... php artisan migrate:refresh -- ...


1 Answers

I've fixed issue by following steps:

  1. First I run command php artisan vendor:publish --tag="cashier-migrations". It will create a new migrations and I've removed code of up() and down() method from new migrations.

By doing this we can keep our override migration of Cashier package.

  1. Run command php artisan migrate
like image 172
Milan Avatar answered Oct 27 '22 10:10

Milan