NWidArt\Modules\Exceptions\ModuleNotFoundException : Module[Blog]Does not exist!, the execution of the database migration file in the module (no need to publish)
1. When the file module.json is deleted under modules/blog, a new migration file is generated: nwidart\modules\exceptions\moduleNotFoundException : module[Blog]does not exist!. as shown in Figure 1
PS E:\wwwroot\laravel6-modules-demo> php artisan module:make-migration delete_wp_is_default_theme_id_from_theme_saas_task_table Blog
Nwidart\Modules\Exceptions\ModuleNotFoundException : Module [Blog] does not exist!
at E:\wwwroot\laravel6-modules-demo\vendor\nwidart\laravel-modules\src\FileRepository.php:396
392| if ($module !== null) {
393| return $module;
394| }
395|
> 396| throw new ModuleNotFoundException("Module [{$name}] does not exist!");
397| }
398|
399| /**
400| * Get all modules as laravel collection instance.
Exception trace:
1 Nwidart\Modules\FileRepository::findOrFail("Blog")
E:\wwwroot\laravel6-modules-demo\vendor\nwidart\laravel-modules\src\Traits\ModuleCommandTrait.php:16
2 Nwidart\Modules\Commands\MigrationMakeCommand::getModuleName()
E:\wwwroot\laravel6-modules-demo\vendor\nwidart\laravel-modules\src\Commands\MigrationMakeCommand.php:115
Please use the argument -v to see more details.
2. Use the make:migration artisan command to create a migration, and use the –path option to customize the personal storage path that generates the migration file. as shown in Figure 2
PS E:\wwwroot\laravel6-modules-demo> php artisan make:migration delete_wp_is_default_theme_id_from_theme_saas_task_table --path=Modules/Blog/Database/Migrations
Created Migration: 2023_01_09_073351_delete_wp_is_default_theme_id_from_theme_saas_task_table
PS E:\wwwroot\laravel6-modules-demo>
3. Generally, the migration in the module needs to be released, but since the module blog no longer exists, it cannot be published.
PS E:\wwwroot\laravel6-modules-demo> php artisan module:publish-migration Blog
Nwidart\Modules\Exceptions\ModuleNotFoundException : Module [Blog] does not exist!
at E:\wwwroot\laravel6-modules-demo\vendor\nwidart\laravel-modules\src\FileRepository.php:396
392| if ($module !== null) {
393| return $module;
394| }
395|
> 396| throw new ModuleNotFoundException("Module [{$name}] does not exist!");
397| }
398|
399| /**
400| * Get all modules as laravel collection instance.
Exception trace:
1 Nwidart\Modules\FileRepository::findOrFail("Blog")
E:\wwwroot\laravel6-modules-demo\vendor\nwidart\laravel-modules\src\Commands\PublishMigrationCommand.php:32
2 Nwidart\Modules\Commands\PublishMigrationCommand::handle()
E:\wwwroot\laravel6-modules-demo\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
Please use the argument -v to see more details.
4. Finally decided to modify the service loading class ServiceProvider of the blog module
/**
*
* @return void
*/
public function register()
{
// ...
$this->registerMigrations();
$this->registerPublishing();
}
/**
* Register the package's migrations.
*
* @return void
*/
private function registerMigrations()
{
if ($this->app->runningInConsole()) {
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
$this->loadFactoriesFrom(__DIR__.'/../Database/factories');
}
}
/**
* Register the package's publishable resources.
*
* @return void
*/
private function registerPublishing()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../Database/Migrations' => database_path('migrations'),
], 'theme-store-db-migrations');
}
}
5. It is no longer necessary to publish the data migration files in the module. When performing the database migration, the database migration files in the module blog will be automatically run.
E:\wwwroot\laravel6-modules-demo> php artisan migrate
Migrating: 2023_01_09_154319_delete_wp_is_default_theme_id_from_theme_saas_task_table
Migrated: 2023_01_09_154319_delete_wp_is_default_theme_id_from_theme_saas_task_table (0 seconds)
E:\wwwroot\laravel6-modules-demo>
6. Even if the database migration file to be executed, there are in the directory: /database/migrations, and in the module directory: /modules/themestoredb/database/migrations , it will also be automatically executed in the chronological order of creation.
PS E:\wwwroot\object> php artisan migrate
Migrating: 2022_12_20_145928_create_theme_saas_task_table
Migrated: 2022_12_20_145928_create_theme_saas_task_table (0.05 seconds)
Migrating: 2023_01_04_094154_add_from_theme_installation_ids_to_theme_saas_task_table
Migrated: 2023_01_04_094154_add_from_theme_installation_ids_to_theme_saas_task_table (0.04 seconds)
Migrating: 2023_01_09_155849_drop_wp_is_default_theme_id_from_theme_saas_task_table
Migrated: 2023_01_09_155849_drop_wp_is_default_theme_id_from_theme_saas_task_table (0.04 seconds)
PS E:\wwwroot\object>
![当在 Modules/Blog 下删除了文件 module.json 后,生成新的迁移文件:Nwidart\Modules\Exceptions\ModuleNotFoundException : Module [Blog] does not exist!](https://www.shuijingwanwq.com/wp-content/uploads/2023/01/1-3.png)
