← Back to Course

Creating and Running Migrations

Migrations give a Laravel application a reliable, version-controlled way to build and evolve its database schema. Instead of applying changes manually on each environment, migrations describe those changes once, in code that travels with the rest of the project.

Creating a Migration

New migrations are generated through Artisan, producing a timestamped file inside database/migrations. The timestamp ensures migrations always run in the order they were created, which matters when later files depend on tables created earlier.

Structuring a Migration

Each migration file defines two methods: up(), which describes the changes to apply, and down(), which describes how to reverse them. This pairing is what makes migrations safely reversible.

CommandWhat It Does
php artisan make:migration create_posts_tableCreates a new migration file
php artisan migrateRuns all pending migrations
php artisan migrate:rollbackReverses the most recent batch of migrations
php artisan migrate:freshDrops all tables and re-runs every migration from scratch

Why Migrations Matter

Creating tables is only the starting point — real applications constantly evolve, which means migrations are just as often used to add columns and modify existing tables.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course