Migrations work as a version control for databases. If you want to keep a record of your database creation and alterations over time, you can use migrations and simplify application re-deployment or distribution. Migrations will help you interact with your database by only using the CLI interface of Laravel. This means that after you install your application and configure the database connection, you just have to run “php artisan migrate” and it will instantly set up the database again.
For migrations, you need to have the following installed:
composer create-project laravel/laravel TestingMigrations
The default user and password will be “root” and empty, respectively.
Finally, after this, you’ll be able to see your Database Management System, where you can alter your databases already present or you’ll be able to see the tables created in the Laravel application.
*Execute the following command in the terminal:
php artisan make:migration create_users_table
If it gives you an error, delete the old migration and make this new one. Your new migrations will be created in the migration sub-directory of database directory of your application. It includes two functions:
Up function (responsible for making tables) Down function (responsible for dropping tables)
Add the following code in the up and down function of the created migration
Go the localhost and check if you can see your table.
Migrations commands along with their uses:
||Make migrations in your app|
||Run your migrations|
||Force running your migrations|
||Rollback last 6 migrations|
If you want to keep on reading about Migrations in Laravel, you can try: