{"id":127546,"date":"2024-04-15T22:55:31","date_gmt":"2024-04-16T02:55:31","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/?p=127546"},"modified":"2024-05-10T10:07:48","modified_gmt":"2024-05-10T14:07:48","slug":"basics-of-laravel-migrations","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/","title":{"rendered":"Basics of Laravel Migrations"},"content":{"rendered":"<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"538\" src=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations-1024x538.png\" alt=\"Basics of Laravel migrations\" class=\"wp-image-127547\" srcset=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations-1024x538.png 1024w, https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations-300x158.png 300w, https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations-768x403.png 768w, https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png 1200w\" sizes=\"auto, (min-width: 1360px) 876px, (min-width: 960px) calc(61.58vw + 51px), calc(100vw - 80px)\" \/><\/figure>\n\n\n\n<p>For any web application or website, managing the integrity and consistency of a database schema over time can be a challenge, particularly when working within collaborative team environments or across various deployment stages. <a href=\"https:\/\/laravel.com\">Laravel<\/a> offers a robust feature known as <strong>migrations<\/strong> that simplifies this process. Migrations act as version control for your database, enabling developers to modify, share, and track changes to the application\u2019s database schema in a reliable manner. This comprehensive guide introduces the basics of Laravel migrations, providing essential knowledge and practical skills to effectively implement and manage database migrations.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#understanding\">Understanding Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#preparing\">Preparing for Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#creating\">Creating Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#running\">Running Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#rolling-back\">Rolling Back Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#advanced\">Advanced Migration Operations<\/a><\/li>\n\n\n\n<li><a href=\"#best-practices\">Best Practices for Managing Migrations<\/a><\/li>\n\n\n\n<li><a href=\"#troubleshooting\">Troubleshooting Common Migration Issues<\/a><\/li>\n\n\n\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding\">Understanding Migrations<\/h2>\n\n\n\n<p><strong>Migrations<\/strong> serve as a method for tracking changes to a database schema over time, effectively allowing teams to apply and share these changes systematically. Each migration file in Laravel includes methods that describe how to apply and roll back database changes, thus offering a way to version control your database setup. This capability is crucial for several reasons:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Collaboration and Consistency<\/h4>\n\n\n\n<p>Migrations are essential in team-based development environments. They ensure that all members of a team are working with the same database schema without needing to manually adjust database states or share SQL dumps. This streamlined approach not only saves time but also reduces the risk of inconsistencies between development, staging, and production environments.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Simplified Deployment<\/h4>\n\n\n\n<p>With migrations, deploying changes to different environments becomes a seamless process. You can push updates to your repository, and migrations can be executed as part of the deployment process to ensure that your database schema matches the application\u2019s requirements automatically. This eliminates the manual effort typically involved in deploying database changes, which can be error-prone and time-consuming.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Easy Reversion<\/h4>\n\n\n\n<p>One of the significant advantages of migrations is the ability to quickly revert changes to an earlier database schema version without impacting the current data. This feature is crucial during times when a new schema change leads to unforeseen issues, and a rollback is necessary to maintain the integrity and availability of the application.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Development Efficiency<\/h4>\n\n\n\n<p>Migrations speed up the development process by allowing developers to quickly set up their local development environment to match the application\u2019s current schema state. This means new team members or contributors can get up and running quickly, without needing to perform complex database syncs.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Safe and Incremental Schema Evolution<\/h4>\n\n\n\n<p>Migrations allow the database schema to evolve incrementally, ensuring that each change is applied in a controlled and staged manner. This incremental approach helps minimize disruptions and detect potential issues early, facilitating smoother transitions as the application scales.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"preparing\">Preparing for Migrations<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites<\/h3>\n\n\n\n<p>Before diving into creating migrations, you must ensure that your Laravel environment is correctly set up:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure Laravel is installed and properly configured.<\/li>\n\n\n\n<li>Verify that the database connection settings are correctly specified in the <code>.env<\/code> file.<\/li>\n\n\n\n<li>Confirm that <code>artisan<\/code>, Laravel\u2019s command-line interface, is functioning and accessible for managing migrations.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Migration Files<\/h3>\n\n\n\n<p>Migrations are stored within the <code>database\/migrations<\/code> directory. Files are typically named to include a timestamp of their creation to help Laravel determine the order of execution. This systematic naming convention helps in managing and understanding the flow of database schema evolution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating\">Creating Migrations<\/h2>\n\n\n\n<p>Creating a migration is straightforward with Laravel\u2019s Artisan command-line tool. To create a new migration, you can use the <code>php artisan make:migration<\/code> command:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"php artisan make:migration create_users_table --create=users\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">artisan<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">make:migration<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">create_users_table<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">--create=users<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\">This command generates a new migration file for creating a <code>users<\/code> table. The migration file will be located in the <code>database\/migrations<\/code> directory, named with a timestamp and the specified name <code>create_users_table<\/code>.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Structure of a Migration File<\/h3>\n\n\n\n<p>A typical migration file contains two primary methods:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>up()<\/code>: Defines the changes to apply to the database such as creating new tables or modifying existing ones.<\/li>\n\n\n\n<li><code>down()<\/code>: Defines how to revert the changes made by the <code>up()<\/code> method, essentially rolling back to the previous database schema state.<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"&lt;?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nreturn new class extends Migration\n{\n    \/**\n     * Run the migrations.\n     *\/\n    public function up(): void\n    {\n        Schema::create('users', function (Blueprint $table) {\n            $table-&gt;id();\n            $table-&gt;string('first_name');\n            $table-&gt;string('last_name');\n            $table-&gt;string('email')-&gt;unique();\n            $table-&gt;timestamp('email_verified_at')-&gt;nullable();\n            $table-&gt;string('password');\n            $table-&gt;rememberToken();\n            $table-&gt;timestamps();\n        });\n\n        Schema::create('password_reset_tokens', function (Blueprint $table) {\n            $table-&gt;string('email')-&gt;primary();\n            $table-&gt;string('token');\n            $table-&gt;timestamp('created_at')-&gt;nullable();\n        });\n\n        Schema::create('sessions', function (Blueprint $table) {\n            $table-&gt;string('id')-&gt;primary();\n            $table-&gt;foreignId('user_id')-&gt;nullable()-&gt;index();\n            $table-&gt;string('ip_address', 45)-&gt;nullable();\n            $table-&gt;text('user_agent')-&gt;nullable();\n            $table-&gt;longText('payload');\n            $table-&gt;integer('last_activity')-&gt;index();\n        });\n    }\n\n    \/**\n     * Reverse the migrations.\n     *\/\n    public function down(): void\n    {\n        Schema::dropIfExists('users');\n        Schema::dropIfExists('password_reset_tokens');\n        Schema::dropIfExists('sessions');\n    }\n};\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F97583\">&lt;?<\/span><span style=\"color: #79B8FF\">php<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Illuminate\\Database\\Migrations\\Migration<\/span><span style=\"color: #E1E4E8\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Illuminate\\Database\\Schema\\Blueprint<\/span><span style=\"color: #E1E4E8\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">use<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #79B8FF\">Illuminate\\Support\\Facades\\Schema<\/span><span style=\"color: #E1E4E8\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F97583\">return<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">new<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">class<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">extends<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">Migration<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #6A737D\">\/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">     * Run the migrations.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">     *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">public<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">up<\/span><span style=\"color: #E1E4E8\">()<\/span><span style=\"color: #F97583\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">void<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">create<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'users'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> (<\/span><span style=\"color: #79B8FF\">Blueprint<\/span><span style=\"color: #E1E4E8\"> $table) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">id<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'first_name'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'last_name'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">unique<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">timestamp<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email_verified_at'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'password'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">rememberToken<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">timestamps<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        });<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">create<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'password_reset_tokens'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> (<\/span><span style=\"color: #79B8FF\">Blueprint<\/span><span style=\"color: #E1E4E8\"> $table) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">primary<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'token'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">timestamp<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'created_at'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        });<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">create<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'sessions'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> (<\/span><span style=\"color: #79B8FF\">Blueprint<\/span><span style=\"color: #E1E4E8\"> $table) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'id'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">primary<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">foreignId<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'user_id'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">()<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">index<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'ip_address'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">45<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">text<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'user_agent'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">longText<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'payload'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">            $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">integer<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'last_activity'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">index<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        });<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #6A737D\">\/**<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">     * Reverse the migrations.<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A737D\">     *\/<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    <\/span><span style=\"color: #F97583\">public<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #B392F0\">down<\/span><span style=\"color: #E1E4E8\">()<\/span><span style=\"color: #F97583\">:<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #F97583\">void<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">dropIfExists<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'users'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">dropIfExists<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'password_reset_tokens'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">        <\/span><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">dropIfExists<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'sessions'<\/span><span style=\"color: #E1E4E8\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">};<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Example of Defining Schema<\/h4>\n\n\n\n<p>Here is how you might define a schema within the <code>up()<\/code> method to create a basic <code>users<\/code> table:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"Schema::create('users', function (Blueprint $table) {\n    $table-&gt;id(); \/\/ Auto-incremental primary key\n    $table-&gt;string('name'); \/\/ A name column that accepts strings\n    $table-&gt;string('email')-&gt;unique(); \/\/ A email column that accepts strings that have to be unique\n    $table-&gt;timestamp('email_verified_at')-&gt;nullable(); \/\/ A created_at and updated_at timestamp column\n    $table-&gt;string('password'); \/\/ A password column that accepts strings\n});\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #79B8FF\">Schema<\/span><span style=\"color: #F97583\">::<\/span><span style=\"color: #B392F0\">create<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'users'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #F97583\">function<\/span><span style=\"color: #E1E4E8\"> (<\/span><span style=\"color: #79B8FF\">Blueprint<\/span><span style=\"color: #E1E4E8\"> $table) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">id<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #6A737D\">\/\/ Auto-incremental primary key<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'name'<\/span><span style=\"color: #E1E4E8\">); <\/span><span style=\"color: #6A737D\">\/\/ A name column that accepts strings<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">unique<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #6A737D\">\/\/ A email column that accepts strings that have to be unique<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">timestamp<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email_verified_at'<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">nullable<\/span><span style=\"color: #E1E4E8\">(); <\/span><span style=\"color: #6A737D\">\/\/ A created_at and updated_at timestamp column<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">    $table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'password'<\/span><span style=\"color: #E1E4E8\">); <\/span><span style=\"color: #6A737D\">\/\/ A password column that accepts strings<\/span><\/span>\n<span class=\"line\"><span style=\"color: #E1E4E8\">});<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"running\">Running Migrations<\/h2>\n\n\n\n<p>To apply your migrations to the database, use the following Artisan command:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"php artisan migrate\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">artisan<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">migrate<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This command processes all migration files that have not yet been applied, updating the database schema according to the definitions in the <code>up()<\/code> methods of the migration files. Laravel smartly keeps track of which migrations have already been executed, so only new or unapplied migrations will run.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"rolling-back\">Rolling Back Migrations<\/h2>\n\n\n\n<p>Laravel provides an efficient way to undo migrations through the following command:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"php artisan migrate:rollback\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">artisan<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">migrate:rollback<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>This command rolls back the last batch of migrations, which could include multiple files depending on how they were batched during the migration. For developers needing to completely reset their database schema, the following command can be utilized:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"php artisan migrate:reset\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #B392F0\">php<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">artisan<\/span><span style=\"color: #E1E4E8\"> <\/span><span style=\"color: #9ECBFF\">migrate:reset<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advanced\">Advanced Migration Operations<\/h2>\n\n\n\n<p>Laravel\u2019s migration system is not limited to just creating and rolling back tables but also supports complex schema operations. Here are some advanced operations you might need to perform:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding Indexes<\/h3>\n\n\n\n<p>Indexes can be added to columns to improve the performance of queries involving those columns:<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"$table-&gt;index(['email', 'type']);\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">$table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">index<\/span><span style=\"color: #E1E4E8\">([<\/span><span style=\"color: #9ECBFF\">'email'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #9ECBFF\">'type'<\/span><span style=\"color: #E1E4E8\">]);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Modifying Existing Columns<\/h3>\n\n\n\n<p>When you need to change properties of existing columns, Laravel 11 supports these operations natively (previous versions were through the Doctrine DBAL library). <\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono-NL.ttf\" style=\"font-size:clamp(16px, 1rem, 24px);font-family:Code-Pro-JetBrains-Mono-NL,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:clamp(26px, 1.625rem, 39px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"$table-&gt;string('email', 191)-&gt;change();\" style=\"color:#e1e4e8;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewbox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki github-dark\" style=\"background-color: #24292e\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #E1E4E8\">$table<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">string<\/span><span style=\"color: #E1E4E8\">(<\/span><span style=\"color: #9ECBFF\">'email'<\/span><span style=\"color: #E1E4E8\">, <\/span><span style=\"color: #79B8FF\">191<\/span><span style=\"color: #E1E4E8\">)<\/span><span style=\"color: #F97583\">-&gt;<\/span><span style=\"color: #B392F0\">change<\/span><span style=\"color: #E1E4E8\">();<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"best-practices\">Best Practices for Managing Migrations<\/h2>\n\n\n\n<p>To ensure that your migrations are easy to manage and understand, consider following these best practices:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Keep Migrations Specific:<\/strong> Limit each migration file to handling a single specific change. This makes migrations easier to understand and manage.<\/li>\n\n\n\n<li><strong>Use Descriptive Names:<\/strong> Choose names for your migration files that clearly describe what the migration does. This helps other developers understand the purpose of each migration without needing to read the entire file.<\/li>\n\n\n\n<li><strong>Commit Regularly:<\/strong> Regularly commit your migration files to your version control system. This keeps your team in sync and allows new team members to set up their development environments quickly by running existing migrations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"troubleshooting\">Troubleshooting Common Migration Issues<\/h2>\n\n\n\n<p>While working with migrations, developers might encounter several common issues. Here are a few troubleshooting tips:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Duplicate Column Errors:<\/strong> Make sure that your migrations do not attempt to add columns that already exist in the table. Carefully managing migration files and reviewing them before deployment can help avoid such issues.<\/li>\n\n\n\n<li><strong>Database Connection Errors:<\/strong> Always double-check your database configuration settings in the <code>.env<\/code> file if you encounter connection errors during migration operations. Ensuring that the database server is accessible from your application environment is also crucial.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>Migrations are a vital tool for any Laravel developer, providing a robust method for managing database schemas. They facilitate easy collaboration within teams, streamline the deployment process, and enhance the overall reliability of database operations in Laravel applications. By integrating migrations into your development workflow, you can significantly reduce the likelihood of issues related to database schema changes and improve the efficiency of your development processes.<\/p>\n\n\n<div class=\"jumbotron\">\r\n<p>Boost your Laravel apps with our specialized <a href=\"https:\/\/www.inmotionhosting.com\/laravel-hosting\">Laravel Hosting<\/a>. Experience faster speeds for your Laravel applications and websites thanks to NVMe storage, server protection, dedicated resources, and optimization tools.<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/design.inmotionhosting.com\/assets\/icons\/standard\/check-blue.svg\" alt=\"check mark\" width=\"24\" height=\"24\" \/>99.99% Uptime    <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/design.inmotionhosting.com\/assets\/icons\/standard\/check-blue.svg\" alt=\"check mark\" width=\"24\" height=\"24\" \/>Free SSL    <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/design.inmotionhosting.com\/assets\/icons\/standard\/check-blue.svg\" alt=\"check mark\" width=\"24\" height=\"24\" \/>Dedicated IP Address    <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/design.inmotionhosting.com\/assets\/icons\/standard\/check-blue.svg\" alt=\"check mark\" width=\"24\" height=\"24\" \/>Developer Tools<\/p>\r\n<p><a class=\"btn btn-primary btn-lg\" href=\"https:\/\/www.inmotionhosting.com\/laravel-hosting\">Laravel Hosting<\/a><\/p>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>For any web application or website, managing the integrity and consistency of a database schema over time can be a challenge, particularly when working within collaborative team environments or across various deployment stages. Laravel offers a robust feature known as migrations that simplifies this process. Migrations act as version control for your database, enabling developers<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\"> Read More ><\/a><\/p>\n","protected":false},"author":57032,"featured_media":127547,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4486],"tags":[],"class_list":["post-127546","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Basics of Laravel Migrations | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Basics of Laravel Migrations | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-04-16T02:55:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-10T14:07:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Derrell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Derrell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\"},\"author\":{\"name\":\"Derrell\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/0736f70b4077032374f89709cdc255b7\"},\"headline\":\"Basics of Laravel Migrations\",\"datePublished\":\"2024-04-16T02:55:31+00:00\",\"dateModified\":\"2024-05-10T14:07:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\"},\"wordCount\":1086,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png\",\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\",\"name\":\"Basics of Laravel Migrations | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png\",\"datePublished\":\"2024-04-16T02:55:31+00:00\",\"dateModified\":\"2024-05-10T14:07:48+00:00\",\"description\":\"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png\",\"width\":1200,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Basics of Laravel Migrations\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/0736f70b4077032374f89709cdc255b7\",\"name\":\"Derrell\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/derrell-willis\"],\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/derrellw\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Basics of Laravel Migrations | InMotion Hosting","description":"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/","og_locale":"en_US","og_type":"article","og_title":"Basics of Laravel Migrations | InMotion Hosting","og_description":"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2024-04-16T02:55:31+00:00","article_modified_time":"2024-05-10T14:07:48+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","type":"image\/png"}],"author":"Derrell","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Derrell","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/"},"author":{"name":"Derrell","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/0736f70b4077032374f89709cdc255b7"},"headline":"Basics of Laravel Migrations","datePublished":"2024-04-16T02:55:31+00:00","dateModified":"2024-05-10T14:07:48+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/"},"wordCount":1086,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage"},"thumbnailUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/","name":"Basics of Laravel Migrations | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage"},"thumbnailUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","datePublished":"2024-04-16T02:55:31+00:00","dateModified":"2024-05-10T14:07:48+00:00","description":"Explore the essentials of Laravel migrations, including setup, execution, and benefits for database management.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#primaryimage","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","width":1200,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/basics-of-laravel-migrations\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Basics of Laravel Migrations"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/0736f70b4077032374f89709cdc255b7","name":"Derrell","sameAs":["https:\/\/www.linkedin.com\/in\/derrell-willis"],"url":"https:\/\/www.inmotionhosting.com\/support\/author\/derrellw\/"}]}},"jetpack_featured_media_url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2024\/04\/laravel-migrations.png","jetpack_sharing_enabled":true,"primary_category":{"id":4486,"name":"Laravel","slug":"laravel","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/laravel\/"},"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/127546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/57032"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=127546"}],"version-history":[{"count":3,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/127546\/revisions"}],"predecessor-version":[{"id":127551,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/127546\/revisions\/127551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media\/127547"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=127546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=127546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=127546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}