0
0
Laravelframework~20 mins

Running and rolling back migrations in Laravel - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Migration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run php artisan migrate in Laravel?
You run php artisan migrate in a Laravel project with new migration files. What is the result?
ALaravel applies all pending migrations and updates the database schema accordingly.
BLaravel rolls back the last batch of migrations automatically.
CLaravel only creates migration files but does not change the database.
DLaravel deletes all existing tables and recreates them from scratch.
Attempts:
2 left
💡 Hint
Think about what 'migrate' means in database terms.
state_output
intermediate
2:00remaining
What is the effect of php artisan migrate:rollback?
After running several migrations, you execute php artisan migrate:rollback. What happens to the database?
AThe database is backed up but no schema changes occur.
BAll migrations are rolled back, clearing the entire database schema.
CNo changes happen; the command only shows migration status.
DThe last batch of migrations is reversed, undoing their database changes.
Attempts:
2 left
💡 Hint
Rollback means undo the last step.
📝 Syntax
advanced
2:00remaining
Which command rolls back the last 3 batches of migrations?
You want to undo the last 3 batches of migrations in Laravel. Which command is correct?
Aphp artisan migrate:rollback --step=3
Bphp artisan migrate:rollback -n 3
Cphp artisan migrate:rollback --batches=3
Dphp artisan migrate:rollback 3
Attempts:
2 left
💡 Hint
Check the official Laravel syntax for rollback steps.
🔧 Debug
advanced
2:00remaining
Why does php artisan migrate:rollback fail with 'No migrations to rollback'?
You run php artisan migrate:rollback but get the error 'No migrations to rollback'. What is the most likely reason?
AThe migration files have syntax errors preventing rollback.
BThere are no migrations applied yet to rollback.
CThe database connection is missing in the config file.
DThe rollback command requires a --force flag to run.
Attempts:
2 left
💡 Hint
Think about what rollback needs to undo.
🧠 Conceptual
expert
3:00remaining
What is the difference between php artisan migrate:refresh and php artisan migrate:rollback?
Choose the option that best explains the difference between these two Laravel migration commands.
A<code>migrate:refresh</code> only rolls back the last batch; <code>migrate:rollback</code> rolls back all migrations.
B<code>migrate:refresh</code> creates new migration files; <code>migrate:rollback</code> deletes migration files.
C<code>migrate:refresh</code> rolls back all migrations and then runs them again; <code>migrate:rollback</code> only rolls back the last batch.
D<code>migrate:refresh</code> deletes the database; <code>migrate:rollback</code> backs up the database.
Attempts:
2 left
💡 Hint
Refresh means start fresh by undoing all and reapplying.