DEV Community

Uthman Ehsan
Uthman Ehsan

Posted on

Migrations in Laravel

Migrations are like version control for your database, allowing your team to define and share the application's database schema definition.

If you have ever had to tell a teammate to manually add a column to their local database schema after pulling in your changes from source control, you've faced the problem that database migrations solve.

*Making Migrations
*

One can generate migrations using below artisan commands

 php artisan make:migration create_multisignin_table

Enter fullscreen mode Exit fullscreen mode

Laravel is smart enough to generate up and down functions under migrations folder with date and migration name under

 database/migrations/2023_09_28_create_multisign_table.php (File)

Enter fullscreen mode Exit fullscreen mode

with auto code generated for up and down methods.

** Running Migrations
**
To run all of your outstanding migrations, execute the migrate Artisan command:

 php artisan migrate

Enter fullscreen mode Exit fullscreen mode

If you created more migrations and they are not migrated yet, to run only a specific migration use this:

php artisan migrate --path=/database/migrations/2023_09_28_create_multisign_table.php
Enter fullscreen mode Exit fullscreen mode

** Above migrations will only run if there is no entry before in the migrations table.**

*_ Check migrations table , if there is an entry for 2023_09_28_create_multisign_table than this particular migration
wont run at all even running either of above commands. *

In order to run the migration , one has to delete the entry from database manually and execute

 php artisan migrate:refresh

Enter fullscreen mode Exit fullscreen mode

Happy Coding !

Top comments (0)