The demand for free, open-source PHP framework is soaring sky-high, so as the empty seats to be fulfilled by niche professionals. We will discuss the database migration present in Laravel, which represents many crucial Laravel interview questions to practice for aspiring candidates looking out to be standalone among others. Migration is a version control mechanism present in Laravel which allows schema of the database to be shared and modified easily. Migrations are paired with the schema builder of Laravel to support the easy build of application's database schema.
In Laravel, data migration is beneficial when developers require migrating schema from one server to another. It is also necessary to operate multiple executions such as alter, create, and drop. Users can also rollback with the help of database migration if any undesired operation gets executed. Migration also helps in keeping a record of the creation and alteration of the database.
php artisan make:migration create_users_table
database/migrations
.–create
and –table
options to refer to whether migration will create a new table and indicate the name of the table. These options will be pre-filled in the generated migration stub file with the user-specified table.make:migration
command.Any data migration class contains two methods, up() and down(). While the up methods are used to add new columns, tables, and indexes to the database, users can reverse the operations performed by the up methods by using the down method. Now to run all our outstanding data migrations, we have to follow these steps.
php artisan migrate
--force
the flag can be used to force the commands to operate without a prompt.php artisan migrate –force
php artisan migrate:rollback
php artisan migrate:rollback --step= X
We can put the number of rollbacks here replacing the X above.