{"id":11615,"date":"2020-03-03T12:30:10","date_gmt":"2020-03-03T12:30:10","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=11615"},"modified":"2021-11-12T06:43:02","modified_gmt":"2021-11-12T06:43:02","slug":"migration-in-laravel","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/migration-in-laravel\/","title":{"rendered":"Migration in Laravel."},"content":{"rendered":"\n<p>Migrations are like version control for our database. Means we don&#8217;t have to worry about versions of the database and laravel because it interacts with the database by command, we don&#8217;t need to interact with the database manually. By using migration, we create\/define tables, structures, seeds value in the database. We also don&#8217;t need to add columns manually in the database.<\/p>\n\n\n\n<h2 class=\"has-text-align-center has-luminous-vivid-orange-color has-text-color wp-block-heading\">How to create a migration.<\/h2>\n\n\n\n<p>To create migration we call a command, see below:- <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"441\" height=\"60\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/create-migration.png\" alt=\"\" class=\"wp-image-11622\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/create-migration.png 441w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/create-migration-300x41.png 300w\" sizes=\"auto, (max-width: 441px) 100vw, 441px\" \/><\/figure><\/div>\n\n\n\n<p>After hitting <strong>Enter<\/strong> migration creates. See below how it looks:- <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"466\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migration-code.png\" alt=\"\" class=\"wp-image-11641\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migration-code.png 447w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migration-code-288x300.png 288w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"has-text-align-center has-luminous-vivid-orange-color has-text-color wp-block-heading\">How to add columns in Database by migration.<\/h2>\n\n\n\n<p>To add a column, we open our migration and add column in <strong>up<\/strong> function and use migrate command to add in database. See below how:- <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"469\" height=\"570\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/column-in-migration.png\" alt=\"\" class=\"wp-image-11646\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/column-in-migration.png 469w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/column-in-migration-247x300.png 247w\" sizes=\"auto, (max-width: 469px) 100vw, 469px\" \/><\/figure><\/div>\n\n\n\n<p>After adding column we call migrate command to add in the database.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"439\" height=\"52\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migrate-command.png\" alt=\"\" class=\"wp-image-11650\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migrate-command.png 439w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/Migrate-command-300x36.png 300w\" sizes=\"auto, (max-width: 439px) 100vw, 439px\" \/><\/figure><\/div>\n\n\n\n<p>Column migrated in database. See below:- <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"868\" height=\"469\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/database-table.png\" alt=\"\" class=\"wp-image-11652\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/database-table.png 868w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/database-table-300x162.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/03\/database-table-768x415.png 768w\" sizes=\"auto, (max-width: 868px) 100vw, 868px\" \/><\/figure><\/div>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_27055\"><iframe loading=\"lazy\"  id=\"_ytid_46042\"  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_27055\"  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","protected":false},"excerpt":{"rendered":"<p>Migrations are like version control for our database. Means we don&#8217;t have to worry about versions of the database and laravel because it interacts with the database by command, we&#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-11615","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\/11615","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=11615"}],"version-history":[{"count":20,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11615\/revisions"}],"predecessor-version":[{"id":24900,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/11615\/revisions\/24900"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=11615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=11615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=11615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}