Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Laravel

Laravel Migrations Deep Dive

Go beyond create table: rollbacks, batching, raw SQL, and safe production migration habits.

Laravel Migrations Deep Dive — a practical guide to Laravel migration best practices with clear examples you can reuse in real projects.

Laravel Tutorial Series (23/27). Prefer one page? Read the complete Laravel tutorial (all 27 topics).

Short description

Migrations are more than `migrate` once — learn rollback strategy, modifying columns, and production safety.

Useful commands

php artisan migrate
php artisan migrate:rollback
php artisan migrate:rollback --step=1
php artisan migrate:fresh --seed   # wipe + remigrate (dev only)
php artisan migrate:status

Rename / change columns (doctrine/dbal may be required on older Laravel)

Schema::table('posts', function (Blueprint $table) {
    $table->renameColumn('body', 'content');
});

Raw SQL inside migration

DB::statement('ALTER TABLE posts ADD FULLTEXT(title, content)');

Production tips

• Take a DB backup first

• Avoid `migrate:fresh` on production

• Keep migrations reversible when possible

• Test rollback on staging

Leave a reply

Your email address will not be published. Required fields are marked *