What are the most used artisan commands for migration in Laravel?
Overview
In this shot, we wil go over the most used artisan commands for migration in Laravel.
Commands
php artisan make:migration table_namecreates a schema for the table. We can edit the schema to suit the needs of our application.
Note:
make:migrationtries to guess the name of the table, so ensure that thetable_namerepresents what you want to name the table.
-
make:migrationcreates a database migration. -
php artisan migratepublishes all our schema to the database. This command also creates the table in the database. -
php artisan migrate:statuschecks the status of the migration. -
migrate:statuschecks the migrations we have run. -
php artisan migrate --forcepublishes schema to the database, even in production.migrate --forceensures that the migrations are published even when the application is in product mode. -
php artisan migrate:rollbackreverses the last migration batch.
Note: Only the latest migration is rolled back, rather than all the migrations. That might involve more than one file.
-
php artisan migrate:resetreverses all migration, unlike:rollback. -
php artisan migrate:freshis used when we want a fresh or new installation of our database. It deletes all the existing tables of the database and runs themigratecommand. -
php artisan migrate:refreshis a two in one command that executes the:rollbackcommand and themigratecommand.
In this instance, the
migrate:rollbackis done on all the migrations. It is very similar to themigrate:fresh.
php artisan migrate:fresh --seedexecutes themigrate:freshcommand, but then itseedsthe database. We can use this command when we install the application on a new host, so that itseeds(i.e., inserts data) into the database.
These are the most used artisan commands we should have at our fingertips while doing anything related to database migration.