【问题标题】:Getting error while run migrate command in laravel 8在 laravel 8 中运行迁移命令时出错
【发布时间】:2021-08-28 05:37:22
【问题描述】:

我正在使用Laravel Cashier 包。

我在 AppServiceProvider.php 下面添加了 > 启动方法

 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 位于供应商文件夹中。

我想运行我自己的迁移,而不是从供应商那里迁移,那么有什么解决方案可以解决这个问题吗?

【问题讨论】:

  • 在 AppServiceProvider 中添加 Cashier::ignoreMigrations(); 后,您删除了所有 tabled 并重新运行迁移?还是直接运行php artisan migrate
  • 我已经运行了 php artisan migrate 命令

标签: php migration laravel-8 laravel-cashier


【解决方案1】:

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

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

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

  1. 运行命令php artisan migrate

【讨论】:

    猜你喜欢
    • 2020-10-24
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    • 2021-05-07
    • 2018-12-28
    • 1970-01-01
    • 2019-04-23
    • 2018-03-06
    相关资源
    最近更新 更多