{"id":5494,"date":"2021-03-11T12:17:59","date_gmt":"2021-03-11T12:17:59","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5494"},"modified":"2021-03-11T12:17:59","modified_gmt":"2021-03-11T12:17:59","slug":"explanation-of-database-migrations-in-laravel-5-8","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/","title":{"rendered":"Explanation of Database Migrations in Laravel 5.8"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Migration\u00a0is a way that allows us to create a table in our database, without accessing the database manager such as phpmyadmin or sql lite. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create a migration we should execute the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan make:migration &#91;options] &#91;--] &lt;name><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, in the option we have number options to enter depending upon the requirement. We can see all the options given below:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&#8211;create[=CREATE]The table to be created<br>&#8211;table[=TABLE] The table to migrate<br>&#8211;path[=PATH] The location where the migration file should be created<br>&#8211;realpath Indicate any provided migration file paths are pre-resolved absolute paths<br>&#8211;fullpath Output the full path of the migration<br>-h, &#8211;help Display this help message<br>-q, &#8211;quiet Do not output any message<br>-V, &#8211;version Display this application version<br>&#8211;ansi Force ANSI output<br>&#8211;no-ansi Disable ANSI output<br>-n, &#8211;no-interaction Do not ask any interactive question<br>&#8211;env[=ENV] The environment the command should run under<br>-v|vv|vvv, &#8211;verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once we create the migration we can see a file under Migration-> database. Migrations\u00a0are files which contain a class definition with both an up() and a down() method. The up() method helps to apply changes to the database and the down() method is used to rollback the changes in the database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Example:-\n\nclass CreateCustomersTable extends Migration\r\n{\r\n    \/**\r\n     * Run the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function up()\r\n    {\r\n        Schema::create('customers', function (Blueprint $table) {\r\n            $table->bigIncrements('id');\r\n            $table->string('name');\r\n            $table->timestamps();\r\n        });\r\n    }\r\n\r\n    \/**\r\n     * Reverse the migrations.\r\n     *\r\n     * @return void\r\n     *\/\r\n    public function down()\r\n    {\r\n        Schema::dropIfExists('customers');\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To run all of our outstanding migrations, we can execute the\u00a0Artisan command given below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also once we execute our migrations in the database we do have the option to roll back the latest migration operation, by using the rollback Artisan command. This command rolls back the last &#8220;batch&#8221; of migrations, which may include multiple migration files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate:rollback<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In Laravel we also have an option to rollback and execute the migration simultaneously with an Artisan command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan migrate:refresh<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To see a video for the topic you can follow the video given below:-<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\"  id=\"_ytid_50819\"  width=\"640\" height=\"360\"  data-origwidth=\"640\" data-origheight=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ccYiq4c_igQ?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  epyt-is-override  no-lazyload\" title=\"YouTube player\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"has-normal-font-size wp-block-paragraph\">Follow the other blog in which we will learn about creating tables in the database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Migration\u00a0is a way that allows us to create a table in our database, without accessing the database manager such as [&hellip;]<\/p>\n","protected":false},"author":20,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5049,156],"tags":[5052,5100,886],"class_list":["post-5494","post","type-post","status-publish","format-standard","hentry","category-laravel","category-websites","tag-laravel","tag-migrations","tag-web-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Explanation of Database Migrations in Laravel 5.8 - scmGalaxy<\/title>\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.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Explanation of Database Migrations in Laravel 5.8 - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"Migration\u00a0is a way that allows us to create a table in our database, without accessing the database manager such as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-11T12:17:59+00:00\" \/>\n<meta name=\"author\" content=\"Joydeep M\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joydeep M\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/\"},\"author\":{\"name\":\"Joydeep M\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"headline\":\"Explanation of Database Migrations in Laravel 5.8\",\"datePublished\":\"2021-03-11T12:17:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/\"},\"wordCount\":319,\"commentCount\":1,\"keywords\":[\"laravel\",\"Migrations\",\"Web Development\"],\"articleSection\":[\"Laravel\",\"Websites\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/\",\"name\":\"Explanation of Database Migrations in Laravel 5.8 - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-03-11T12:17:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/explanation-of-database-migrations-in-laravel-5-8\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Explanation of Database Migrations in Laravel 5.8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\",\"name\":\"scmGalaxy\",\"description\":\"A Platform for Software Engineers\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\",\"name\":\"Joydeep M\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g\",\"caption\":\"Joydeep M\"},\"description\":\"An investment in knowledge pays the best interest.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/joydeep-kumar-538412208\\\/\"],\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/author\\\/joydeep\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Explanation of Database Migrations in Laravel 5.8 - scmGalaxy","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.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/","og_locale":"en_US","og_type":"article","og_title":"Explanation of Database Migrations in Laravel 5.8 - scmGalaxy","og_description":"Migration\u00a0is a way that allows us to create a table in our database, without accessing the database manager such as [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/","og_site_name":"scmGalaxy","article_published_time":"2021-03-11T12:17:59+00:00","author":"Joydeep M","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joydeep M","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/"},"author":{"name":"Joydeep M","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"headline":"Explanation of Database Migrations in Laravel 5.8","datePublished":"2021-03-11T12:17:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/"},"wordCount":319,"commentCount":1,"keywords":["laravel","Migrations","Web Development"],"articleSection":["Laravel","Websites"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/","name":"Explanation of Database Migrations in Laravel 5.8 - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-03-11T12:17:59+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Explanation of Database Migrations in Laravel 5.8"}]},{"@type":"WebSite","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website","url":"https:\/\/www.scmgalaxy.com\/tutorials\/","name":"scmGalaxy","description":"A Platform for Software Engineers","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.scmgalaxy.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6","name":"Joydeep M","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fb490db5d492c960456cc628f9e832fda72c5bc426cd8a13b18cbb95bca7ce99?s=96&d=mm&r=g","caption":"Joydeep M"},"description":"An investment in knowledge pays the best interest.","sameAs":["https:\/\/www.linkedin.com\/in\/joydeep-kumar-538412208\/"],"url":"https:\/\/www.scmgalaxy.com\/tutorials\/author\/joydeep\/"}]}},"_links":{"self":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/users\/20"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/comments?post=5494"}],"version-history":[{"count":1,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5494\/revisions"}],"predecessor-version":[{"id":5495,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5494\/revisions\/5495"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}