{"id":820,"date":"2020-02-13T04:26:40","date_gmt":"2020-02-13T04:26:40","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/02\/13\/create-schema-file-to-create-new-database-table-in-magento-2-3\/"},"modified":"2025-05-22T14:59:03","modified_gmt":"2025-05-22T09:29:03","slug":"create-schema-file-to-create-new-database-table-in-magento-2-3","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-schema-file-to-create-new-database-table-in-magento-2-3\/","title":{"rendered":"How To Create Schema File To Create New Database Table In Magento 2.3"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A database table to save the Magento 2 store data can be created using two methods. One of the methods to create a new database table in Magento 2.3 is with the db_schema.xml file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The post shows how to <strong>create schema file to create new database table in Magento 2.3.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apart from the below code, you can refer <a href=\"https:\/\/developer.adobe.com\/commerce\/docs\/#db_schema-structure\" target=\"_blank\" rel=\"noreferrer noopener\">DB schema structure<\/a> for Magento 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Create Schema File To Create New Database Table in Magento 2.3:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create <strong>db_schema.xm<\/strong>l file at <strong>app\/code\/Vendor\/Extension\/etc\/ directory<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;schema xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd\">\n&lt;table name=\"mt_distance_shipping_warehouse\" resource=\"default\" engine=\"innodb\" comment=\"Distance Shipping Warehouse Table\">\n    &lt;column xsi:type=\"int\" name=\"id\" padding=\"10\" unsigned=\"true\" nullable=\"false\" identity=\"true\" comment=\"ID\"\/>\n    &lt;column xsi:type=\"varchar\" name=\"longitude\" comment=\"Longitude\" nullable=\"false\"\/>\n    &lt;column xsi:type=\"varchar\" name=\"latitude\" comment=\"Latitude\" nullable=\"false\"\/>\n    &lt;column xsi:type=\"varchar\" name=\"street\" comment=\"Street\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"varchar\" name=\"city\" comment=\"City\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"varchar\" name=\"state\" comment=\"State\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"varchar\" name=\"country\" comment=\"Country\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"varchar\" name=\"zipcode\" comment=\"Zipcode\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"boolean\" name=\"status\" comment=\"Status\" nullable=\"false\" \/>\n    &lt;column xsi:type=\"timestamp\" name=\"created_at\" on_update=\"false\" nullable=\"false\" default=\"CURRENT_TIMESTAMP\" comment=\"Created At\"\/>\n    &lt;column xsi:type=\"timestamp\" name=\"updated_at\" on_update=\"true\" nullable=\"false\" default=\"CURRENT_TIMESTAMP\" comment=\"Updated At\"\/>\n    &lt;constraint xsi:type=\"primary\" referenceId=\"PRIMARY\">\n        &lt;column name=\"id\"\/>\n    &lt;\/constraint>\n&lt;\/table>\n&lt;\/schema><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next step is to create a new database table in Magento 2.3.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with fellow developers of Magento community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A database table to save the Magento 2 store data can be created using two methods. One of the methods to create a new database&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-820","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=820"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/820\/revisions"}],"predecessor-version":[{"id":15086,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/820\/revisions\/15086"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}