Updated on Jul 11, 2024
Earlier in this tutorial, we mentioned that migrations can insert tables directly into your application's database without actually opening it. Such migrations can be done via the Artisan CLI with a few commands. In this part, we will lay them out and explain what each does. In the previous section, we mentioned another command: php artisan make:migration. That is the fundamental command when it comes to inserting new tables into your database. After the command, you must specify a name for the table, and if it is more than one word, each word has to be separated from the rest via an underscore, with no empty spaces. Here is an example.
php artisan make:migration fastcomet_table_one
Once the creation process is completed, you will see a confirmation message. The new migration will be placed in your application's database/migrations directory, and each file within the directory has a timestamp. This allows Laravel to determine the order of creation.
With that said, here are the remainder of the migration-related commands that you can use to manage your database's table.
php artisan migrate:fresh - Drops all tables and re-runs all migrations, effectively resetting your database and then executing the migrate command;
php artisan migrate:install - Creates the migration repository, which is typically not created by default;
Migrations are especially useful when a whole team is working on an application. That way, they don't have to pass the database's actual file and import it every time they have made a change. With migrations, changes to the database can be made and reverted on the spot.