{"id":16217,"date":"2025-05-20T15:42:25","date_gmt":"2025-05-20T11:42:25","guid":{"rendered":"https:\/\/www.temok.com\/blog\/?p=16217"},"modified":"2025-09-17T15:10:34","modified_gmt":"2025-09-17T11:10:34","slug":"laravel-migration","status":"publish","type":"post","link":"https:\/\/www.temok.com\/blog\/laravel-migration\/","title":{"rendered":"Laravel Migration: Best Practices For Smooth Database Changes"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 8<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span><p>To manage database changes in Laravel applications, Laravel migration is essential. They provide an organized strategy for coordinating the codebase of your application and database across different settings.<\/p>\n<p>Additionally, envision your application changing over time, necessitating the installation of additional tables or modifications to the database structure. However, Laravel creates migration saves this procedure from turning into a laborious, error-prone manual operation.<\/p>\n<p>A detailed history of modifications made in the order they were generated is ensured by timestamped migration files. However, this makes things easier, such as implementing changes gradually or going back to former states.<\/p>\n<p>Migrations provide a more dependable and tidy method of managing database modifications. Moreover, they enable you to specify modifications in a methodical, repeatable, and error-proof way. Your database structure will remain consistent across all settings thanks to well-written migration scripts, which eliminate the need for manual intervention.<\/p>\n<p>Keep reading and exploring to learn what are migrations in Laravel and how to create Laravel default date value migration.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16223 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?resize=750%2C500&#038;ssl=1\" alt=\"Laravel Migration\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a4e5006e6a40\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a4e5006e6a40\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#What_Are_Migrations_in_Laravel\" >What Are Migrations in Laravel?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#What_Are_The_Benefits_of_Laravel_Migration\" >What Are The Benefits of Laravel Migration?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Database_Version_Control\" >Database Version Control<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Simpler_Retractions\" >Simpler Retractions<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Uniformity_Throughout_Environments\" >Uniformity Throughout Environments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Manual_SQL_is_Not_Necessary\" >Manual SQL is Not Necessary<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Consistency_Of_The_Codebase\" >Consistency Of The Codebase<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Management_Of_Dependencies\" >Management Of Dependencies<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Facilitating_Collaboration\" >Facilitating Collaboration<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#How_To_Create_a_Migration_in_Laravel\" >How To Create a Migration in Laravel?<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Create_a_Migration\" >Create a Migration<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Describe_The_Schema\" >Describe The Schema<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Including_Columns_In_The_Table\" >Including Columns In The Table<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#4_Executing_the_Migration\" >4.\u00a0 Executing the Migration<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Additional_Laravel_Migration_Commands\" >Additional Laravel Migration Commands<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Including_in_the_index\" >Including in the index:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Renaming_Index\" >Renaming Index:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Eliminating_The_Index\" >Eliminating The Index<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Applying_Constraints_for_Foreign_Keys\" >Applying Constraints for Foreign Keys<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Laravel_Migration_Best_Practices_For_Smooth_Database_Changes\" >Laravel Migration Best Practices For Smooth Database Changes<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Make_Migrations_Easy\" >Make Migrations Easy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Write_Down_The_Modifications\" >Write Down The Modifications<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Employ_Evocative_Names\" >Employ Evocative Names<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Utilize_Version_Control\" >Utilize Version Control<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Local_Test_Migrations\" >Local Test Migrations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Make_A_Backup_Of_Your_Production_Database\" >Make A Backup Of Your Production Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Evaluate_Every_Migration\" >Evaluate Every Migration<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#FAQs_Frequently_Asked_Questions\" >FAQs (Frequently Asked Questions)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#What_Is_Laravel_Migration\" >What Is Laravel Migration?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#What_Is_The_Best_Practice_For_Laravel_Migration\" >What Is The Best Practice For Laravel Migration?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#How_To_Migrate_PHP_to_Laravel\" >How To Migrate PHP to Laravel?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/www.temok.com\/blog\/laravel-migration\/#How_To_Migrate_Laravel_To_Another_Server\" >How To Migrate Laravel To Another Server?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_Are_Migrations_in_Laravel\"><\/span><strong>What Are Migrations in Laravel?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The Laravel Migration set of instructions outlines the changes you want to apply to your database schema. However, these changes could call for establishing new tables, editing already-existing ones, seeding the database with initial data, or adding or modifying columns.<\/p>\n<p>Regardless of whether you&#8217;re using <a href=\"https:\/\/blog.temok.com\/postgresql-vs-mysql\/\" target=\"_blank\" rel=\"noopener\">PostgreSQL and MySQL<\/a>, SQLite, or any Laravel-supported database system, you can do Laravel create migration without worrying about it. Migrations are portable and adaptable to other database systems because the framework abstracts away the syntax unique to each database.<\/p>\n<p>However, there is an up method for defining the modifications and a down method for undoing them in every migration file. The database schema is updated to the most recent version when you execute PHP artisan make: controller resource model and migration, which applies all outstanding migrations.<\/p>\n<p>Laravel 11 has added several enhancements to the framework as a whole, such as:<\/p>\n<ul>\n<li>The application structure has been simplified for improved organization.<\/li>\n<li>Rate limitation per second for more accurate processing of API requests.<\/li>\n<li>A new health routing directive that automatically provides a basic health-check destination.<\/li>\n<li>For better safety, use a graceful encryption key rotation.<\/li>\n<li>Enhancements to queue testing to facilitate task testing.<\/li>\n<li>Automate routine chores using new Artisan commands.<\/li>\n<li>For real-time applications, Laravel Reverb is an integrated WebSocket server.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"What_Are_The_Benefits_of_Laravel_Migration\"><\/span><strong>What Are The Benefits of Laravel Migration?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Because of its many advantages, Laravel migration is\u00a0an essential component of every serious Laravel project. Let&#8217;s dissect these benefits:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Database_Version_Control\"><\/span><strong>Database Version Control<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your database&#8217;s migrations act as a version control system, preserving consistency across development, classification, and production environments. A common database schema makes it possible for all developers working on a project to apply the same changes without having to manually communicate with one another.<\/p>\n<p><strong>Also Read:<\/strong> <a href=\"https:\/\/blog.temok.com\/laravel-best-security-practices\/\" target=\"_blank\" rel=\"noopener\">Laravel Best Security Practices: An Overview<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Simpler_Retractions\"><\/span><strong>Simpler Retractions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Reverting database schema changes is made easier with Laravel. Moreover, you may simply roll back a Laravel\u00a0migration if it produces a mistake or unanticipated problems, which is crucial flexibility for keeping a reliable and clean database.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Uniformity_Throughout_Environments\"><\/span><strong>Uniformity Throughout Environments<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can keep your local, staging, and manufacturing databases in sync by using PHP artisan make migration. However, by using the same migration scripts, you can easily duplicate the exact schema in each environment, reducing discrepancies and errors.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Manual_SQL_is_Not_Necessary\"><\/span><strong>Manual SQL is Not Necessary<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Writing intricate and prone to errors SQL queries is no longer necessary, thanks to Laravel database select type Laravel migrations, which enable you to specify database structure changes using a clear and expressive vocabulary. Moreover, check out Temok\u2019s one of the best and most affordable <a href=\"https:\/\/www.temok.com\/managed-laravel-cloud-hosting\" target=\"_blank\" rel=\"noopener\">Managed Laravel Cloud Hosting<\/a> plans in 2025!<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Consistency_Of_The_Codebase\"><\/span><strong>Consistency Of The Codebase<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can make sure that all project developers can implement database changes consistently across all settings, from local development configurations to production servers, by encapsulating them in a create migration in Laravel files.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Management_Of_Dependencies\"><\/span><strong>Management Of Dependencies<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Managing intricate database modifications that depend on the presence of specific structures becomes easier with the dependency management function.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Facilitating_Collaboration\"><\/span><strong>Facilitating Collaboration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Teams can monitor and communicate database changes to all team members because of Laravel migration. Moreover, it\u00a0guarantees\u00a0that all developers use the same schema by enabling fresh Laravel create database migration\u00a0to be downloaded from a common source.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_To_Create_a_Migration_in_Laravel\"><\/span><strong>How To Create a Migration in Laravel?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16225 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?resize=750%2C500&#038;ssl=1\" alt=\"How To Create a Migration in Laravel\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/How-To-Create-a-Migration-in-Laravel.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Controlling your <a href=\"https:\/\/blog.temok.com\/database-security\/\" target=\"_blank\" rel=\"noopener\">database security<\/a> schema changes requires creating a migration in Laravel. To have a better understanding of its structure, let&#8217;s create a small Laravel database\u00a0migration.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Create_a_Migration\"><\/span><strong>Create a Migration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The PHP artisan make migration\u00a0command in Laravel is used to construct a Laravel\u00a0migration. Go to the directory of your Laravel project by opening your terminal. Next, execute the subsequent command:<\/p>\n<pre><code>php artisan make:controller --resource --model=ModelName --migration<\/code><\/pre>\n<p>A new migration file with the name 2024_09_18_000000_create_example_table.php will be created in the database\/migrations directory as a result of this command. Migrations are carried out in the order in which they were made, thanks to the timestamp in the filename.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16227 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?resize=750%2C500&#038;ssl=1\" alt=\"Create a Migration\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Create-a-Migration.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Describe_The_Schema\"><\/span><strong>Describe The Schema<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use a code editor or your preferred <a href=\"https:\/\/phoenixnap.com\/kb\/command-line-text-editor\" target=\"_blank\" rel=\"noopener\">command-line text editor<\/a> to open the freshly produced migration file. The migration file has two methods: up and down. The down technique outlines how to undo the Laravel migration\u00a0you wish to make to your database schema, whereas the up method outlines the changes you wish to make.<\/p>\n<p>The following is a representation of a straightforward Laravel create database migration\u00a0that generates a table named example with two columns:<\/p>\n<pre><code>use Illuminate\\Database\\Migrations\\Migration;\r\n\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\n\u00a0\r\n\r\nClass CreateExampleTable extends migration\r\n\r\n{\r\n\r\npublic function up()\r\n\r\n{\r\n\r\nSchema::create('example', function (Blueprint $table) {\r\n\r\n$table-&gt;bigIncrements('id');\r\n\r\n$table-&gt;string('name');\r\n\r\n$table-&gt;text('description')-&gt;nullable();\r\n\r\n$table-&gt;timestamps();\r\n\r\n});\r\n\r\n}\r\n\r\npublic function down()\r\n\r\n{\r\n\r\nSchema::dropIfExists('example');\r\n\r\n}\r\n\r\n}<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Including_Columns_In_The_Table\"><\/span><strong>Including Columns In The Table<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To generate a new migration file that adds a new column to the sample table, use the following command:<\/p>\n<pre><code>PHP artisan make migration add_new_column_to_example_table --table=example<\/code><\/pre>\n<p>Making changes to the migration file:<\/p>\n<p>Change the up and down methods as follows after opening the freshly generated migration file (2024_09_18_45678_add_new_column_to_example_table.php, for example):<\/p>\n<pre><code>\r\nuse Illuminate\\Database\\Migrations\\Migration;\r\n\r\nuse Illuminate\\Database\\Schema\\Blueprint;\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\nclass AddNewColumnToExampleTable extends migration\r\n\r\n{\r\n\r\npublic function up()\r\n\r\n{\r\n\r\nSchema::table('example', function (Blueprint $table) {\r\n\r\n$table-&gt;string('new_column')-&gt;nullable();\r\n\r\n});\r\n\r\n}\r\n\r\npublic function down()\r\n\r\n{\r\n\r\nSchema::table('example', function (Blueprint $table) {\r\n\r\n$table-&gt;dropColumn('new_column');\r\n\r\n});\r\n\r\n}\r\n\r\n}\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"4_Executing_the_Migration\"><\/span><strong>4.\u00a0 <\/strong><strong>Executing the Migration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Use the following Artisan command to apply the Laravel migration and generate the sample table in your database:<\/p>\n<pre><code>PHP Artisan Migration<\/code><\/pre>\n<p>All pending migrations are carried out using this command. In your database&#8217;s migrations table, Laravel records which migrations were earlier performed.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16228 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?resize=750%2C500&#038;ssl=1\" alt=\"Executing the Migration\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Executing-the-Migration.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Additional_Laravel_Migration_Commands\"><\/span><strong>Additional Laravel Migration Commands<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16229 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?resize=750%2C500&#038;ssl=1\" alt=\"Additional Commands\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Additional-Laravel-Migration-Commands.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Adding, altering, or deleting database indexes may be accomplished with Laravel migrations. Let&#8217;s examine each of these steps step-by-step.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Including_in_the_index\"><\/span><strong>Including in the index:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>use Illuminate\\Database\\Schema\\Blueprint;\r\n\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\nSchema::table('users', function (Blueprint $table) {\r\n\r\n$table-&gt;index('email');\r\n\r\n}\r\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Renaming_Index\"><\/span><strong>Renaming Index: <\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To change the name of an index, use<\/p>\n<pre><code>renameIndex():\r\n\r\n$table-&gt;renameIndex('email', 'mobile_no');\r\n\r\n}\r\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Eliminating_The_Index\"><\/span><strong>Eliminating The Index<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To remove an index, you can utilize<\/p>\n<pre><code>dropIndex():\r\n\r\n$table-&gt;dropIndex('email');\r\n\r\n}\r\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Applying_Constraints_for_Foreign_Keys\"><\/span><strong>Applying Constraints for Foreign Keys<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Foreign key constraints, which guarantee that the data in your database remains consistent and adheres to the connections between various tables, may be created using Laravel.<\/p>\n<pre><code>{$table-&gt;foreignId('id')\r\n\r\nconstrained('users')\r\n\r\ncascadeOnUpdate()\r\n\r\ncascadeOnDelete();}\r\n<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Laravel_Migration_Best_Practices_For_Smooth_Database_Changes\"><\/span><strong>Laravel Migration Best Practices For Smooth Database Changes<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-16230 size-full\" src=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?resize=750%2C500&#038;ssl=1\" alt=\"Best Practices For Smooth Database Changes\" width=\"750\" height=\"500\" srcset=\"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?w=750&amp;ssl=1 750w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?resize=300%2C200&amp;ssl=1 300w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?resize=24%2C16&amp;ssl=1 24w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?resize=36%2C24&amp;ssl=1 36w, https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration-Best-Practices-For-Smooth-Database-Changes.webp?resize=48%2C32&amp;ssl=1 48w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Database schema changes can be efficiently managed using Laravel migrations, but there are certain recommended practices to follow. These crucial pointers will help you maintain production-ready, clean, and managed migrations and improve <a href=\"https:\/\/blog.temok.com\/laravel-performance-optimization\/\" target=\"_blank\" rel=\"noopener\">Laravel performance optimization<\/a>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Make_Migrations_Easy\"><\/span><strong>Make Migrations Easy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Making several little migrations is preferable to making one big one. This method makes it simpler to track and identify problems as they occur. A single, logical Laravel create migration, such as adding a column or establishing a table, should be made during each transfer.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Write_Down_The_Modifications\"><\/span><strong>Write Down The Modifications<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Writing out the necessary adjustments is generally a smart idea before you begin scripting your migration. Moreover, this will lower the likelihood of mistakes by helping you define exactly what has to be done. Having a documented strategy can ensure that your Laravel\u00a0migration is accurate, whether you&#8217;re adding columns, changing relationships, or establishing new tables.<\/p>\n<p>For example, if you want to add a new column called &#8220;contact&#8221; to the &#8220;users&#8221; table, you should write:<\/p>\n<pre><code>Table: users\r\n\r\nAdd the contact column (integer, nullable).<\/code><\/pre>\n<p>Additionally, you can ensure that your migration meets the requirements of your application and avoid team misunderstandings by clearly communicating the changes.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Employ_Evocative_Names\"><\/span><strong>Employ Evocative Names<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Give each migration file a clear and descriptive name so that it is apparent what it accomplishes. To specify the precise operation, for example, use names like create_users_table or add_email_to_users_table.<\/p>\n<p><strong>Also Read:<\/strong> <a href=\"https:\/\/blog.temok.com\/server-migration\/\" target=\"_blank\" rel=\"noopener\">Server Migration Process With Useful Tips And Important Checklists<\/a><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Utilize_Version_Control\"><\/span><strong>Utilize Version Control<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>When working with migrations, using Git or another version control system is necessary. Additionally, migrations should have a commitment to the code for your application as you track your codebase. However, version control provides several important advantages:<\/p>\n<ul>\n<li>Working together ensures that everyone in the team adheres to the same template.<\/li>\n<li>If necessary, reversibility enables you to undo code and migrations.<\/li>\n<li>You can keep track of who made modifications to the database and when they were made due to traceability.<\/li>\n<\/ul>\n<p>Version control ensures seamless database migrations across various environments and team members in large projects. However, you should handle each Laravel\u00a0migration as a crucial component of the architecture of your program.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Local_Test_Migrations\"><\/span><strong>Local Test Migrations<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Run migrations locally on a new database before putting changes into production to make sure everything goes as planned. However, by testing migrations, you may prevent surprises on live databases and identify any issues. It will also help to <a href=\"https:\/\/blog.temok.com\/host-laravel-website-or-app\/\" target=\"_blank\" rel=\"noopener\">host Laravel website or app<\/a>.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Make_A_Backup_Of_Your_Production_Database\"><\/span><strong>Make A Backup Of Your Production Database<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Make a database backup before doing any migrations in production. In the event that something goes wrong during the migration, this precaution reduces the chance of data loss.<\/p>\n<p>However, you may handle a\u00a0Laravel migration\u00a0using a dependable method that reduces risks by utilizing unambiguous naming and backing up production databases.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Evaluate_Every_Migration\"><\/span><strong>Evaluate Every Migration<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Before implementing any move to a production environment, testing is crucial. However, this is made simple by Laravel, which enables you to use PHP Artisan migration to do migrations in local or staging environments. You may safely deploy the migration to production after you&#8217;ve verified that everything functions as it should.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Handling changes to database schemas reliably and efficiently is one of the advantages of a Laravel migration. Thanks to the version control system offered by Laravel database select type migrations and approved methods, your databases will be consistent, easily configurable, and able to be rolled back if necessary.<\/p>\n<p>Together, these advantages improve the development process, increasing its dependability and efficiency while also enhancing the maintainability of Laravel applications. Moreover, you can make sure that your migrations are dependable, effective, and well-documented by adhering to best practices and techniques. We hope you now understand how to create migration in Laravel.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"FAQs_Frequently_Asked_Questions\"><\/span><strong>FAQs (Frequently Asked Questions)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"What_Is_Laravel_Migration\"><\/span><strong>What Is Laravel Migration?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The modifications you wish to make to your database schema are outlined in the Laravel Migration set of instructions. However, these adjustments may involve adding or changing columns, seeding the database with beginning data, editing already-existing tables, or establishing new tables.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_Is_The_Best_Practice_For_Laravel_Migration\"><\/span><strong>What Is The Best Practice For Laravel Migration?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Schema migrations should only be used for structural modifications. To manage data migrations, use Laravel&#8217;s artisan commands. Moreover, this division offers freedom in data modification while maintaining the cleanliness and focus of your migrations.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_To_Migrate_PHP_to_Laravel\"><\/span><strong>How To Migrate PHP to Laravel?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The first steps in the phased process of migrating a PHP application to Laravel are establishing Laravel, moving the database, and then gradually reviewing the key features and code. However, understanding the fundamental processes and utilizing Laravel&#8217;s built-in features can help one to simplify this approach.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_To_Migrate_Laravel_To_Another_Server\"><\/span><strong>How To Migrate Laravel To Another Server?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Add the files for the Laravel project to your account. Moreover, you can do it via SFTP or the cPanel File Manager.<\/li>\n<li>Moreover, use SSH to access your account.<\/li>\n<li>Additionally, use your favorite text editor to open the index.php file located in the public_html directory.<\/li>\n<li>Lastly, save the index with your modifications.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 8<\/span> <span class=\"rt-label rt-postfix\">min read<\/span><\/span>To manage database changes in Laravel applications, Laravel migration is essential. They provide an organized strategy for coordinating the codebase of your application and database across different settings. Additionally, envision your application changing over time, necessitating the installation of additional tables or modifications to the database structure. However, Laravel creates migration saves this procedure from [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":16223,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"pmpro_default_level":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23],"tags":[4448,4441,4447,4440,4445,4444,4446,4438,4449,4439,4443,4442],"class_list":["post-16217","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development","tag-create-migration-in-laravel","tag-how-to-create-a-migration-in-laravel","tag-laravel-create-database-migration","tag-laravel-create-migration","tag-laravel-database","tag-laravel-database-select-type","tag-laravel-default-date-value-migration","tag-laravel-migration","tag-migration-in-laravel","tag-php-artisan-make-migration","tag-php-artisan-makecontroller-resource-model-and-migration","tag-what-are-migrations-in-laravel","pmpro-has-access"],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blog.temok.com\/wp-content\/uploads\/2025\/05\/Laravel-Migration.webp?fit=750%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/16217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/comments?post=16217"}],"version-history":[{"count":10,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/16217\/revisions"}],"predecessor-version":[{"id":17657,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/posts\/16217\/revisions\/17657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/media\/16223"}],"wp:attachment":[{"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/media?parent=16217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/categories?post=16217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.temok.com\/blog\/wp-json\/wp\/v2\/tags?post=16217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}