Create and run module migrations
To create the posts table for the Blog module, generate a migration inside the module and run it. You need an enabled Blog module and a configured database.
-
Generate the migration. The first word of the name selects the stub (
createwritesSchema::create()).Terminal window php artisan module:make-migration create_posts_table Blog --fields="title:string,body:text"This creates
Modules/Blog/database/migrations/<timestamp>_create_posts_table.phpwith one column percolumn:typepair:Modules/Blog/database/migrations/<timestamp>_create_posts_table.php Schema::create('posts', function (Blueprint $table) {$table->id();$table->string('title');$table->text('body');$table->timestamps();}); -
Run the migrations.
php artisan migrateruns pending migrations for the application and every enabled module in one batch.Terminal window php artisan migrateTo run only one module’s migrations, use
module:migrate:Terminal window php artisan module:migrate Blog -
Check the result.
Terminal window php artisan module:migrate-status BlogMigration name .............................................. Batch / Status<timestamp>_create_posts_table ..................................... [2] RanIn a fresh Laravel app, the application’s own migrations are batch 1, so the new migration runs in batch 2.
Add a column later
Section titled “Add a column later”Name the migration after the action. add_slug_to_posts_table selects the add stub for the posts table:
php artisan module:make-migration add_slug_to_posts_table Blog --fields="slug:string:nullable"This adds $table->string('slug')->nullable() in up() and drops it in down(). Run it with php artisan migrate or php artisan module:migrate Blog.
Pass --plain for an empty migration regardless of the name (--fields is ignored):
php artisan module:make-migration seed_default_posts Blog --plainMigrate a subdirectory or file
Section titled “Migrate a subdirectory or file”Pass --subpath to module:migrate, module:migrate-rollback, or module:migrate-reset to target a subdirectory, a single file, or a glob pattern relative to the module’s migrations directory:
php artisan module:migrate Blog --subpath=tenantphp artisan module:migrate-rollback Blog --subpath=2026_01_01_000000_create_posts_table.phpRoll back
Section titled “Roll back”Undo the last batch of a module with module:migrate-rollback:
php artisan module:migrate-rollback Blogmodule:migrateplaces each module in its own batch;php artisan migrateputs all pending migrations in one batch.- Run
php artisan module:migrate-reset Blogto roll back all migrations in the module. - Run
php artisan module:migrate-refresh Blogto reset and re-run them. With--all, it refreshes enabled modules only in ascendingpriorityorder; naming a module runs it regardless of status. - In
production, rollback, reset, and refresh commands ask for confirmation unless you pass--force.
Control migration auto-discovery
Section titled “Control migration auto-discovery”By default, modules.auto-discover.migrations is true in config/modules.php, so the package registers every enabled module’s migration path with Laravel’s migrator.
Setting it to false stops that package-level hook. Modules extending ModuleServiceProvider still load their own migrations in boot(), so disabling auto-discover.migrations only skips modules without ModuleServiceProvider (such as --plain modules) during php artisan migrate. module:migrate is unaffected.
Publish the migrations to the application
Section titled “Publish the migrations to the application”Copy a module’s migrations into database/migrations (for example before removing the module):
php artisan module:publish-migration BlogExisting files are skipped unless you pass --force. Because filenames stay the same, Laravel tracks each migration once even if it exists in both locations.
Related
Section titled “Related”- Database commands: every
module:migrate*command and option. - Module migrations and
php artisan migrate auto-discoverconfigurationmodule:make-migrationandmodule:publish-migration- Add Eloquent models to a module
- Seed a module with factories and seeders