{"id":3203,"date":"2022-07-01T10:11:36","date_gmt":"2022-07-01T10:11:36","guid":{"rendered":"https:\/\/www.cynoinfotech.com\/?p=3203"},"modified":"2022-07-01T10:24:39","modified_gmt":"2022-07-01T10:24:39","slug":"magento-2-how-to-create-table-and-field-using-db_schema-xml","status":"publish","type":"post","link":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/","title":{"rendered":"Magento 2 How to create table and field using db_schema.xml"},"content":{"rendered":"<p>In this blog, we\u2019re going to show you how to use the db_schema.xml file to create a new database table.<\/p>\n<p>Once you Create file\u00a0<strong>db_schema.xml <\/strong>in this directory <strong>app\/code\/VName\/MName\/etc. <\/strong>We will create a table named\u00a0 <strong>&#8220;<\/strong><strong>table_name&#8221;<\/strong>.<\/p>\n<pre class=\"lang:default decode:true \">&lt;schema xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\nxsi:noNamespaceSchemaLocation=\"urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd\"&gt;\n     &lt;table name=\"table_name\"&gt;\n       &lt;column xsi:type=\"int\" name=\"id\" padding=\"10\" unsigned=\"true\" nullable=\"false\" comment=\"Entity Id\"\/&gt;\n       &lt;column xsi:type=\"varchar\" name=\"title\" nullable=\"false\" length=\"255\" comment=\"Title\"\/&gt;\n       &lt;column xsi:type=\"timestamp\" name=\"time_occurred\" comment=\"Time of event\"\/&gt;\n       &lt;column xsi:type=\"int\" name=\"status\" nullable=\"false\" default=\"0\" comment=\"status\"\/&gt;\n       &lt;column xsi:type=\"mediumtext\" name=\"description\" nullable=\"true\" comment=\"Description\"\/&gt;\n       &lt;constraint xsi:type=\"primary\" referenceId=\"PRIMARY\"&gt;\n        &lt;column name=\"id\"\/&gt;\n        &lt;\/constraint&gt;\n     &lt;\/table&gt;\n&lt;\/schema&gt;\n<\/pre>\n<p><strong>After will running the below command :<\/strong><\/p>\n<ul>\n<li><strong>php bin\/magento setup:upgrade<\/strong><\/li>\n<\/ul>\n<p>As you run the upgrade command, a new database table will be created in your database.<\/p>\n<p>If you have any questions let me know in the comment section.<\/p>\n<p>Thank you!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this blog, we\u2019re going to show you how to use the db_schema.xml file to create a new database table. Once you Create file\u00a0db_schema.xml in this directory app\/code\/VName\/MName\/etc. We will create a table named\u00a0 &#8220;table_name&#8221;. &lt;schema xmlns:xsi=&#8221;http:\/\/www.w3.org\/2001\/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=&#8221;urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd&#8221;&gt; &lt;table name=&#8221;table_name&#8221;&gt; &lt;column xsi:type=&#8221;int&#8221; name=&#8221;id&#8221; padding=&#8221;10&#8243; unsigned=&#8221;true&#8221; nullable=&#8221;false&#8221; comment=&#8221;Entity Id&#8221;\/&gt; &lt;column xsi:type=&#8221;varchar&#8221; name=&#8221;title&#8221; nullable=&#8221;false&#8221; length=&#8221;255&#8243; comment=&#8221;Title&#8221;\/&gt; &lt;column [&hellip;]<\/p>\n","protected":false},"author":670,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3203","post","type-post","status-publish","format-standard","hentry","category-magento-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Magento 2 How to create table and field using db_schema.xml - cynoinfotech<\/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:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/\"},\"author\":{\"name\":\"Arjun Makadiya\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\"},\"headline\":\"Magento 2 How to create table and field using db_schema.xml\",\"datePublished\":\"2022-07-01T10:11:36+00:00\",\"dateModified\":\"2022-07-01T10:24:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/\"},\"wordCount\":98,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"articleSection\":[\"Magento blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/\",\"name\":\"Magento 2 How to create table and field using db_schema.xml - cynoinfotech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\"},\"datePublished\":\"2022-07-01T10:11:36+00:00\",\"dateModified\":\"2022-07-01T10:24:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/magento-2-how-to-create-table-and-field-using-db_schema-xml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Magento 2 How to create table and field using db_schema.xml\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"name\":\"cynoinfotech\",\"description\":\"web design &amp; development\",\"publisher\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#organization\",\"name\":\"Cynoinfotech\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"contentUrl\":\"https:\\\/\\\/www.cynoinfotech.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/final-logo-ci.png\",\"width\":240,\"height\":70,\"caption\":\"Cynoinfotech\"},\"image\":{\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/cynoinfotech\\\/\",\"https:\\\/\\\/x.com\\\/cynoinfotech\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/#\\\/schema\\\/person\\\/f1be8186602d3ebf417cf58baf125f24\",\"name\":\"Arjun Makadiya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g\",\"caption\":\"Arjun Makadiya\"},\"description\":\"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.\",\"url\":\"https:\\\/\\\/cynoinfotech.com\\\/blog\\\/author\\\/arjun-makadiya\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Magento 2 How to create table and field using db_schema.xml - cynoinfotech","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:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/#article","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/"},"author":{"name":"Arjun Makadiya","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24"},"headline":"Magento 2 How to create table and field using db_schema.xml","datePublished":"2022-07-01T10:11:36+00:00","dateModified":"2022-07-01T10:24:39+00:00","mainEntityOfPage":{"@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/"},"wordCount":98,"commentCount":0,"publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"articleSection":["Magento blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/","url":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/","name":"Magento 2 How to create table and field using db_schema.xml - cynoinfotech","isPartOf":{"@id":"https:\/\/cynoinfotech.com\/blog\/#website"},"datePublished":"2022-07-01T10:11:36+00:00","dateModified":"2022-07-01T10:24:39+00:00","breadcrumb":{"@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cynoinfotech.com\/blog\/magento-2-how-to-create-table-and-field-using-db_schema-xml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cynoinfotech.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Magento 2 How to create table and field using db_schema.xml"}]},{"@type":"WebSite","@id":"https:\/\/cynoinfotech.com\/blog\/#website","url":"https:\/\/cynoinfotech.com\/blog\/","name":"cynoinfotech","description":"web design &amp; development","publisher":{"@id":"https:\/\/cynoinfotech.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cynoinfotech.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cynoinfotech.com\/blog\/#organization","name":"Cynoinfotech","url":"https:\/\/cynoinfotech.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","contentUrl":"https:\/\/www.cynoinfotech.com\/wp-content\/uploads\/2017\/11\/final-logo-ci.png","width":240,"height":70,"caption":"Cynoinfotech"},"image":{"@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cynoinfotech\/","https:\/\/x.com\/cynoinfotech"]},{"@type":"Person","@id":"https:\/\/cynoinfotech.com\/blog\/#\/schema\/person\/f1be8186602d3ebf417cf58baf125f24","name":"Arjun Makadiya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d1792fe07de4cbcd8b55a0a55e79e3a67f4df3ab63af6b0738833c83cac0eab3?s=96&d=mm&r=g","caption":"Arjun Makadiya"},"description":"Arjun Makadiya is a Junior Magento Developer at Cynoifotech. He is passionate about technology. Apart from work he likes to play cricket.","url":"https:\/\/cynoinfotech.com\/blog\/author\/arjun-makadiya\/"}]}},"_links":{"self":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/users\/670"}],"replies":[{"embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=3203"}],"version-history":[{"count":7,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3203\/revisions"}],"predecessor-version":[{"id":3211,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/3203\/revisions\/3211"}],"wp:attachment":[{"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=3203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=3203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cynoinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=3203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}