{"id":11656,"date":"2020-03-04T07:15:34","date_gmt":"2020-03-04T07:15:34","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=11656"},"modified":"2021-11-12T06:42:11","modified_gmt":"2021-11-12T06:42:11","slug":"rolling-back-migration-in-laravel","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/rolling-back-migration-in-laravel\/","title":{"rendered":"Rolling Back migration in  Laravel."},"content":{"rendered":"\n<p><strong>Rollback<\/strong> command is used to rollback the last migration means remove the last migration from the database. Laravel provides different commands to rollback tables from the database, these are:- <\/p>\n\n\n\n<p><strong><em>1. php artisan migrate:rollback<\/em><\/strong> :- It rollback the last migration we have migrated. See below:-<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"180\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/rolback-command.png\" alt=\"\" class=\"wp-image-11666\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/rolback-command.png 581w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/rolback-command-300x93.png 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/figure><\/div>\n\n\n\n<p><strong><em>2. php artisan migrate:rollback &#8211;step=(No.-of-migrations)<\/em><\/strong> :- It rollback the limited number of last migrations (no. is provided after <strong>step<\/strong>) from the database. See below:-<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"622\" height=\"224\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/step-migration.png\" alt=\"\" class=\"wp-image-11678\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/step-migration.png 622w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/step-migration-300x108.png 300w\" sizes=\"auto, (max-width: 622px) 100vw, 622px\" \/><\/figure><\/div>\n\n\n\n<p>In the above example, <strong>Step=3<\/strong> means it rollback last 3 migrations. So after the execution of command as you see that last 3 migrations are rollbacked.<\/p>\n\n\n\n<p><strong><em>3. php artisan migrate:reset<\/em><\/strong>  :-  It will rollback all the migrations from the database with only one command.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"232\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-reset.png\" alt=\"\" class=\"wp-image-11688\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-reset.png 586w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-reset-300x119.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure><\/div>\n\n\n\n<p>4.  <strong><em>php artisan migrate:refresh<\/em><\/strong> :- After calling refresh, it first <strong>rollback<\/strong> all the migrations and then execute <strong>migrate<\/strong> command automatically. This command effectively re-creates your entire database. See below:- <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"590\" height=\"338\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-refresh.png\" alt=\"\" class=\"wp-image-11696\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-refresh.png 590w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/migration-refresh-300x172.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/figure><\/div>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_87103\"><iframe loading=\"lazy\"  id=\"_ytid_68686\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?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__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_87103\"  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><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rollback command is used to rollback the last migration means remove the last migration from the database. Laravel provides different commands to rollback tables from the database, these are:- 1&#8230;. <\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5201],"tags":[5203],"class_list":["post-11656","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=11656"}],"version-history":[{"count":30,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11656\/revisions"}],"predecessor-version":[{"id":24899,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11656\/revisions\/24899"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=11656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=11656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=11656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}