Skip to content

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.

  1. Generate the migration. The first word of the name selects the stub (create writes Schema::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.php with one column per column:type pair:

    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();
    });
  2. Run the migrations. php artisan migrate runs pending migrations for the application and every enabled module in one batch.

    Terminal window
    php artisan migrate

    To run only one module’s migrations, use module:migrate:

    Terminal window
    php artisan module:migrate Blog
  3. Check the result.

    Terminal window
    php artisan module:migrate-status Blog
    Migration name .............................................. Batch / Status
    <timestamp>_create_posts_table ..................................... [2] Ran

    In a fresh Laravel app, the application’s own migrations are batch 1, so the new migration runs in batch 2.

Name the migration after the action. add_slug_to_posts_table selects the add stub for the posts table:

Terminal window
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):

Terminal window
php artisan module:make-migration seed_default_posts Blog --plain

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:

Terminal window
php artisan module:migrate Blog --subpath=tenant
php artisan module:migrate-rollback Blog --subpath=2026_01_01_000000_create_posts_table.php

Undo the last batch of a module with module:migrate-rollback:

Terminal window
php artisan module:migrate-rollback Blog
  • module:migrate places each module in its own batch; php artisan migrate puts all pending migrations in one batch.
  • Run php artisan module:migrate-reset Blog to roll back all migrations in the module.
  • Run php artisan module:migrate-refresh Blog to reset and re-run them. With --all, it refreshes enabled modules only in ascending priority order; naming a module runs it regardless of status.
  • In production, rollback, reset, and refresh commands ask for confirmation unless you pass --force.

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.

Copy a module’s migrations into database/migrations (for example before removing the module):

Terminal window
php artisan module:publish-migration Blog

Existing files are skipped unless you pass --force. Because filenames stay the same, Laravel tracks each migration once even if it exists in both locations.