0
0
Laravelframework~15 mins

Running and rolling back migrations in Laravel - Mini Project: Build & Apply

Choose your learning style9 modes available
Running and Rolling Back Migrations in Laravel
📖 Scenario: You are building a Laravel application that needs a database table to store information about books. You will create a migration to add the books table, run the migration to create the table in the database, and then learn how to roll back the migration if needed.
🎯 Goal: Create a migration file for the books table, run the migration to apply it to the database, and then roll back the migration to remove the table.
📋 What You'll Learn
Create a migration file named create_books_table
Run the migration using the correct Artisan command
Roll back the last migration using the correct Artisan command
💡 Why This Matters
🌍 Real World
Managing database changes safely and efficiently is essential in real-world Laravel projects to keep the database schema in sync with application code.
💼 Career
Understanding migrations and how to run or roll them back is a fundamental skill for Laravel developers working on team projects or maintaining production applications.
Progress0 / 4 steps
1
Create the migration file
Use the Artisan command php artisan make:migration create_books_table to create a migration file named create_books_table.
Laravel
Need a hint?

Open your terminal and type the exact command to create a migration file named create_books_table.

2
Run the migration to create the table
Run the Artisan command php artisan migrate to apply all pending migrations, including the create_books_table migration.
Laravel
Need a hint?

Use the command that applies all migrations to the database.

3
Roll back the last migration
Use the Artisan command php artisan migrate:rollback to undo the last batch of migrations, which will remove the books table.
Laravel
Need a hint?

Use the command that rolls back the last migration batch.

4
Confirm migration rollback
Check the database or use the Artisan command php artisan migrate:status to confirm that the books table migration has been rolled back.
Laravel
Need a hint?

Use the command that shows the status of all migrations to verify rollback.