在 Laravel 8 中运行迁移命令时出现错误

6

我正在使用 Laravel Cashier 包。

我已在 AppServiceProvider.php 中的 boot 方法中添加了以下行:

 Cashier::ignoreMigrations();

我创建了自己的迁移,例如:create_subscriptions_table和create_subscription_items_table。

当我运行php artisan migrate命令时,会收到以下错误:

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

我之所以出现这个错误,是因为迁移2019_05_03_000002_create_subscriptions_table在vendor文件夹中。

我想运行自己的迁移而不是从vendor中运行,有没有解决此问题的方法?


在 AppServiceProvider 中添加 Cashier::ignoreMigrations(); 后,您是否删除了所有表并重新运行迁移?还是只需运行 php artisan migrate - Mohammad Hosseini
我已经运行了php artisan migrate命令。 - Milan
1个回答

4

我通过以下步骤解决了问题:

  1. 首先,我运行了命令php artisan vendor:publish --tag="cashier-migrations"。它会创建一个新的迁移,并且我已经从新的迁移中删除了up()和down()方法的代码。

通过这样做,我们可以保留Cashier包的覆盖迁移。

  1. 运行命令php artisan migrate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接