Laravel — P28: Migrations

Dino Cajic
Geek Culture
Published in
8 min readJan 12, 2023

--

Dino Cajic on Laravel Migrations

Migrations are a way for everyone on the team to easily share database schemas. Once you create a migration, everyone on the team will be able to run it and generate a new table. There is no more messaging others and telling them that they need to add a new column or change the column type. Upload the migrations and if something breaks, the team can run the migrations again to update the tables.

How Do You Create a Migration?

Generating a migration is just another artisan command. I told you that we would be using artisan a lot. The command itself is make:migration.

php artisan make:migration create_tests_table

This new migration will be added to the database/migrations directory. There, you’ll find the migration named and a timestamp prepended to it. We want the files to have a unique name and to be placed in order since the migrations will run from top to bottom. In other words, we may have migrations that depend on other tables that already exist. If we run a migration and that dependency table does not exist, you will get an error. Most of the time it’s because the table is not in the correct order. If you ever happen to find that that’s the case, you can rename the file and add a timestamp that comes before.

--

--

Dino Cajic
Geek Culture

Author of An Illustrative Introduction to Algorithms. IT Leader with a B.S. in Computer Science, a minor in Biology, and a passion for learning.