没有不值得去解决的问题,也没有不值得去学习的技术!

Roll Back and Rerun Database Migrations in Laravel 6 Modules When “Migration not found” Occurs

To roll back the last migration operation, you can use the Artisan command rollback. This command rolls back the last "batch" of migrations, which may include multiple migration files, but it prompts: Migration not found

1. I noticed some changes in the database migration files in the Git repository, such as the field mine_type being changed to mime_type. See Figure 1.

I noticed some changes in the database migration files in the Git repository, such as the field mine_type being changed to mime_type.
Figure 1

2. These two database migration files happened to be in the last migration batch. See Figure 2.

These two database migration files happened to be in the last migration batch
Figure 2

3. To roll back the last migration operation, you can use the Artisan command rollback. This command rolls back the last “batch” of migrations, which may include multiple migration files, but it prompts: Migration not found. See Figure 3.

To roll back the last migration operation, you can use the Artisan command rollback. This command rolls back the last "batch" of migrations, which may include multiple migration files, but it prompts: Migration not found
Figure 3
Plaintext

PS E:\wwwroot\object> php artisan migrate:rollback
Migration not found: 2021_12_13_145303_create_theme_asset_version_table
Migration not found: 2021_12_06_133918_create_theme_asset_table
PS E:\wwwroot\object>

4. The reason should be that these two migration files are located inside a module, at the path: /Modules/ThemeStore/Database/Migrations, and do not exist in the default path: /database/migrations.

5. The module implementation is based on nwidart/laravel-modules, so I executed the module:migrate-rollback command. The execution was successful. See Figure 4.

The module implementation is based on nwidart/laravel-modules, so I executed the module:migrate-rollback command. The execution was successful
Figure 4
Plaintext

PS E:\wwwroot\object> php artisan module:migrate-rollback ThemeStore
Rollback: 2021_12_13_145303_create_theme_asset_version_table
Rollback: 2021_12_06_133918_create_theme_asset_table
PS E:\wwwroot\object> php artisan module:migrate ThemeStore
Migrating: 2021_12_06_133918_create_theme_asset_table
Migrated:  2021_12_06_133918_create_theme_asset_table (0.26 seconds)
Migrating: 2021_12_13_145303_create_theme_asset_version_table
Migrated:  2021_12_13_145303_create_theme_asset_version_table (0.02 seconds)
PS E:\wwwroot\object>

6. I checked the database table, and the field name has been changed to: mime_type. See Figure 5.

I checked the database table, and the field name has been changed to: mime_type
Figure 5

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系