What is migration?
we can create the table and all the database structure through laravel only we will create a file with structure and migrate that file to the database
php artisan make:migration create_test_table // create means it will create the table
Go to databaseโMigration and you can able to see the created file
In the file you can see two functions
- up() โ will create the table
- down() โ will drop the table
If you want to create some column then you can define inside the up( ) function
Now to migrate this table into the actual database you have to run the following command
php artisan migrate // migrate all the files inside migration folder // some tables are defined by laravel to keep track of migratable files inside the migration so don't delete any predefined file inside migration folder blindly
Question
1. How to invert the migration we have done ?
2. How to migrate only a specific file in the migration folder?
ย
ย
Reset Migration
php artisan migrate:rest // it will remove all the table created by
ย
Rollback
It means to invert a specific file from the current migration
php artisan migrate:rollback // it will revert back the last migration you have made
To rollback previos two migrates we can do like โ
php artisan migrate:rollback --step 2 // it will rollback 2 steps from current migration
ย
Refresh
if anything is not working well with migration then you can refresh the migration that will first rollback all the migrations and then migrate all the files again
php artisan migrate:refresh
ย
Specific file migrations
suppose you want to migrate a specific file so you can run the following command
php artisan migrate --path= _path_relative
ย