{"id":5496,"date":"2021-03-11T12:41:56","date_gmt":"2021-03-11T12:41:56","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=5496"},"modified":"2021-03-11T12:41:56","modified_gmt":"2021-03-11T12:41:56","slug":"creating-tables-in-migration","status":"publish","type":"post","link":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/","title":{"rendered":"Creating tables in Migration"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">In Laravel to create a new database table first of all we need to make a migration which we have explained in the previous blog. I recommend you to read that blog, you can refer the link given below:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br><a href=\"https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/\">https:\/\/www.scmgalaxy.com\/tutorials\/explanation-of-database-migrations-in-laravel-5-8\/<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once we are done with creating a migration file, to create a new database<br>table we have to use the create method on the Schema facade. The create method accepts two arguments:-<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first is the name of the table, while the second is a closure which receives a Blueprint object that may be used to define the new table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use Illuminate\\Database\\Schema\\Blueprint;\r\nuse Illuminate\\Support\\Facades\\Schema;\r\n\r\nSchema::create('users', function (Blueprint $table) {\r\n    $table->id();\r\n    $table->string('name');\r\n    $table->string('email');\r\n    $table->timestamps();\r\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the table we can add number of $table as per our requirement. There are several data type which we can use while creating the $table. Few of them are given below:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-bigIncrements\"><p><code>bigIncrements()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>bigIncrements<\/code>&nbsp;method creates an auto-incrementing&nbsp;<code>UNSIGNED BIGINT<\/code>&nbsp;(primary key) equivalent column:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;bigIncrements(&#039;id&#039;);\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-bigInteger\"><p><code>bigInteger()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>bigInteger<\/code>&nbsp;method creates a&nbsp;<code>BIGINT<\/code>&nbsp;equivalent column:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;bigInteger(&#039;votes&#039;);\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-id\"><p><code>id()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>id<\/code>&nbsp;method is an alias of the&nbsp;<code>bigIncrements<\/code>&nbsp;method. By default, the method will create an&nbsp;<code>id<\/code>&nbsp;column; however, you may pass a column name if you would like to assign a different name to the column:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;id();\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-rememberToken\"><p><code>rememberToken()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>rememberToken<\/code>&nbsp;method creates a nullable,&nbsp;<code>VARCHAR(100)<\/code>&nbsp;equivalent column that is intended to store the current &#8220;remember me&#8221;&nbsp;<a href=\"https:\/\/laravel.com\/docs\/8.x\/authentication#remembering-users\">authentication token<\/a>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;rememberToken();\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-string\"><p><code>string()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>string<\/code>&nbsp;method creates a&nbsp;<code>VARCHAR<\/code>&nbsp;equivalent column of the given length:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;string(&#039;name&#039;, 100);\n<\/pre><\/div>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\" id=\"column-method-text\"><p><code>text()<\/code><\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<code>text<\/code>&nbsp;method creates a&nbsp;<code>TEXT<\/code>&nbsp;equivalent column:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$table-&gt;text(&#039;description&#039;);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">To know more about creating tables and adding columns, you can refer 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_57264\"  width=\"640\" height=\"360\"  data-origwidth=\"640\" data-origheight=\"360\" src=\"https:\/\/www.youtube.com\/embed\/pd99VUe7b0o?enablejsapi=1&#038;list=PLT9miexWCpPXuMenRSnpek96ncK3dXf90&#038;index=13&#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","protected":false},"excerpt":{"rendered":"<p>In Laravel to create a new database table first of all we need to make a migration which we have [&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],"tags":[5052,5102,5101,5063],"class_list":["post-5496","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-laravel","tag-laravel-database","tag-laravel-migrations","tag-laravel-project"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating tables in Migration - 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\/creating-tables-in-migration\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating tables in Migration - scmGalaxy\" \/>\n<meta property=\"og:description\" content=\"In Laravel to create a new database table first of all we need to make a migration which we have [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/\" \/>\n<meta property=\"og:site_name\" content=\"scmGalaxy\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-11T12:41:56+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\\\/creating-tables-in-migration\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/\"},\"author\":{\"name\":\"Joydeep M\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"headline\":\"Creating tables in Migration\",\"datePublished\":\"2021-03-11T12:41:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/\"},\"wordCount\":287,\"commentCount\":0,\"keywords\":[\"laravel\",\"laravel database\",\"laravel migrations\",\"laravel project\"],\"articleSection\":[\"Laravel\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/\",\"url\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/\",\"name\":\"Creating tables in Migration - scmGalaxy\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#website\"},\"datePublished\":\"2021-03-11T12:41:56+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/#\\\/schema\\\/person\\\/8a2c0533775223a96dd307662111bac6\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/creating-tables-in-migration\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.scmgalaxy.com\\\/tutorials\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Creating tables in Migration\"}]},{\"@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":"Creating tables in Migration - 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\/creating-tables-in-migration\/","og_locale":"en_US","og_type":"article","og_title":"Creating tables in Migration - scmGalaxy","og_description":"In Laravel to create a new database table first of all we need to make a migration which we have [&hellip;]","og_url":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/","og_site_name":"scmGalaxy","article_published_time":"2021-03-11T12:41:56+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\/creating-tables-in-migration\/#article","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/"},"author":{"name":"Joydeep M","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"headline":"Creating tables in Migration","datePublished":"2021-03-11T12:41:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/"},"wordCount":287,"commentCount":0,"keywords":["laravel","laravel database","laravel migrations","laravel project"],"articleSection":["Laravel"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/","url":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/","name":"Creating tables in Migration - scmGalaxy","isPartOf":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#website"},"datePublished":"2021-03-11T12:41:56+00:00","author":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/#\/schema\/person\/8a2c0533775223a96dd307662111bac6"},"breadcrumb":{"@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.scmgalaxy.com\/tutorials\/creating-tables-in-migration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.scmgalaxy.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Creating tables in Migration"}]},{"@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\/5496","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=5496"}],"version-history":[{"count":2,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5496\/revisions"}],"predecessor-version":[{"id":5498,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/posts\/5496\/revisions\/5498"}],"wp:attachment":[{"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/media?parent=5496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/categories?post=5496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scmgalaxy.com\/tutorials\/wp-json\/wp\/v2\/tags?post=5496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}