{"id":282286,"date":"2021-02-06T08:50:04","date_gmt":"2021-02-06T08:50:04","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=282286"},"modified":"2024-08-01T09:16:17","modified_gmt":"2024-08-01T09:16:17","slug":"create-database-tables-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/","title":{"rendered":"Create Database Tables in Magento 2"},"content":{"rendered":"\n<p>Before developing the frontend part of the module, let&#8217;s <a href=\"https:\/\/webkul.com\/blog\/how-to-create-a-new-database-table-in-magento-2-0\/\">create some tables<\/a>. It&#8217;s a good idea to create the tables beforehand. Because it helps us visualize the working of the module, which helps us in developing the module step by step.<\/p>\n\n\n\n<p>We will be developing a simple <a href=\"https:\/\/webkul.com\/blog\/magento-blog-manager\/\">blog manager module<\/a> so we need a table to save the blog data and another table to save the comments. If in the future, any other tables are needed or if we have to add\/modify any columns then we can easily do that in Magento.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Declarative Schema<\/strong><\/h2>\n\n\n\n<p>Magento 2 uses a <strong>declarative schema<\/strong> to create the tables. The new declarative schema approach allows developers to declare the final desired state of the database and has the system adjust to it automatically, without performing redundant operations. <\/p>\n\n\n\n<p>Developers are no longer forced to write scripts for each new version. In addition, this approach allows data be deleted when a module is uninstalled.<\/p>\n\n\n\n<p>For declarative schema, we need to create the <strong>db_schema.xml<\/strong> under the, <strong>etc<\/strong> folder.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"1128\" height=\"235\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\" alt=\"Selection_087\" class=\"wp-image-390513\" style=\"width:820px;height:170px\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png 1128w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087-300x63.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087-250x52.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087-768x160.png 768w\" sizes=\"(max-width: 1128px) 100vw, 1128px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Code for <em>etc\/db_schema.xml<\/em> file will be<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;schema xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd&quot;&gt;\n    &lt;table name=&quot;blogmanager_blog&quot; resource=&quot;default&quot; engine=&quot;innodb&quot; comment=&quot;Blogs Table&quot;&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;entity_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; identity=&quot;true&quot; comment=&quot;Entity Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;user_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;Customer\/User Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;varchar&quot; name=&quot;title&quot; nullable=&quot;false&quot; length=&quot;255&quot; comment=&quot;Blog Title&quot;\/&gt;\n        &lt;column xsi:type=&quot;longtext&quot; name=&quot;content&quot; nullable=&quot;false&quot; comment=&quot;Blog Content&quot;\/&gt;\n        &lt;column xsi:type=&quot;smallint&quot; name=&quot;status&quot; padding=&quot;11&quot; unsigned=&quot;false&quot; nullable=&quot;false&quot; default=&quot;0&quot; comment=&quot;Blog Status&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;created_at&quot; on_update=&quot;false&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Creation Time&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;updated_at&quot; on_update=&quot;true&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Updated At&quot;\/&gt;\n        &lt;constraint xsi:type=&quot;primary&quot; referenceId=&quot;PRIMARY&quot;&gt;\n            &lt;column name=&quot;entity_id&quot;\/&gt;\n        &lt;\/constraint&gt;\n        &lt;index referenceId=&quot;BLOGMANAGER_BLOG_USER_ID&quot; indexType=&quot;btree&quot;&gt;\n            &lt;column name=&quot;user_id&quot;\/&gt;\n        &lt;\/index&gt;\n    &lt;\/table&gt;\n    &lt;table name=&quot;blogmanager_comment&quot; resource=&quot;default&quot; engine=&quot;innodb&quot; comment=&quot;Blog Comments Table&quot;&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;entity_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; identity=&quot;true&quot; comment=&quot;Entity Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;blog_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;Blog Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;user_id&quot; padding=&quot;10&quot; unsigned=&quot;true&quot; nullable=&quot;false&quot; comment=&quot;User Id&quot;\/&gt;\n        &lt;column xsi:type=&quot;varchar&quot; name=&quot;screen_name&quot; nullable=&quot;false&quot; length=&quot;255&quot; comment=&quot;Screen Name&quot;\/&gt;\n        &lt;column xsi:type=&quot;text&quot; name=&quot;comment&quot; nullable=&quot;false&quot; comment=&quot;Comment&quot;\/&gt;\n        &lt;column xsi:type=&quot;smallint&quot; name=&quot;status&quot; padding=&quot;11&quot; unsigned=&quot;false&quot; nullable=&quot;false&quot; default=&quot;0&quot; comment=&quot;Status&quot;\/&gt;\n        &lt;column xsi:type=&quot;timestamp&quot; name=&quot;created_at&quot; on_update=&quot;false&quot; nullable=&quot;false&quot; default=&quot;CURRENT_TIMESTAMP&quot; comment=&quot;Creation Time&quot;\/&gt;\n        &lt;constraint xsi:type=&quot;primary&quot; referenceId=&quot;PRIMARY&quot;&gt;\n            &lt;column name=&quot;entity_id&quot;\/&gt;\n        &lt;\/constraint&gt;\n        &lt;constraint xsi:type=&quot;foreign&quot; referenceId=&quot;FK_BLOG_COMMENT&quot; table=&quot;blogmanager_comment&quot; column=&quot;blog_id&quot; referenceTable=&quot;blogmanager_blog&quot; referenceColumn=&quot;entity_id&quot; onDelete=&quot;CASCADE&quot;\/&gt;\n        &lt;index referenceId=&quot;BLOGMANAGER_COMMENT_BLOG_ID&quot; indexType=&quot;btree&quot;&gt;\n            &lt;column name=&quot;blog_id&quot;\/&gt;\n        &lt;\/index&gt;\n    &lt;\/table&gt;\n&lt;\/schema&gt;<\/pre>\n\n\n\n<p>As you can see it is pretty self-explanatory, the table node\/table tag represents the table and the column nodes inside the table node represents each column. We can manage the name, type, length, etc info about a column with the attributes of the tag\/node. <\/p>\n\n\n\n<p>To create constraints like Primary key, and Foreign Key we have to use constraint tag. We can also create indexes with index tag. Here we have created two tables blogmanager_blog, blogmanager_comment.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">db_schema_whitelist<\/h2>\n\n\n\n<p>After creating the db_schema.xml we need to generate the <a href=\"https:\/\/developer.adobe.com\/commerce\/php\/development\/components\/declarative-schema\/configuration\/\">db_schema_whitelist.json<\/a> which provides a history of all tables, columns, and keys added with declarative schema. You don&#8217;t have to worry about this file because it can be generated automatically with a command.<\/p>\n\n\n\n<p> It&#8217;s for backward compatibility and it will be removed in the future.<\/p>\n\n\n\n<p>The db_schema_whitelist. json file is&nbsp;<strong>a way of telling Magento which tables and columns it can safely alter using the db_schema.<\/strong>&nbsp;<strong>xml file<\/strong>.<\/p>\n\n\n\n<p>You can use the following command to generate the db_schema_whitelist.json file<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">php bin\/magento setup:db-declaration:generate-whitelist --module-name=VendorName_ModuleName<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1146\" height=\"103\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_088.png\" alt=\"Selection_088\" class=\"wp-image-390515\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_088.png 1146w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_088-300x27.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_088-250x22.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_088-768x69.png 768w\" sizes=\"(max-width: 1146px) 100vw, 1146px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>It will create db_schema_whitelist.json in the etc folder.<\/p>\n\n\n\n<p>Now to actually process the db_schema.xml and create the tables we need to run the setup upgrade command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">php bin\/magento setup:upgrade<\/pre>\n\n\n\n<p>After successfully running this command, when you check your database you will find the new tables, <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"621\" height=\"572\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12.png\" alt=\"2021-02-06_13-12\" class=\"wp-image-282294\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12.png 621w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12-300x276.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12-250x230.png 250w\" sizes=\"(max-width: 621px) 100vw, 621px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"643\" height=\"738\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12_1.png\" alt=\"2021-02-06_13-12_1\" class=\"wp-image-282295\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12_1.png 643w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12_1-261x300.png 261w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/02\/2021-02-06_13-12_1-217x249.png 217w\" sizes=\"(max-width: 643px) 100vw, 643px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Now suppose that later we decided to change something, we can just do the changes in the db_schema.xml file, regenerate the db_schema_whitelist.json and run the setup upgrade command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install Schema and Upgrade Schema<\/h2>\n\n\n\n<p>The declarative schema is a new addition to Magento. In the earlier version of Magento, before 2.3, we had to use the InstallSchema.php file to create the tables. And if we later decided to make some changes in the table we had to use UpgradeSchema.php. <\/p>\n\n\n\n<p>So first time when we install the module it would run the InstallSchema.php file and for version updates, it would run the UpgradeSchema.php.<\/p>\n\n\n\n<p>Please check out these blogs which explain using these files. Note that it will not work in our module because we have not mentioned the module version number in the module.xml file.<\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/blog\/how-to-create-a-new-database-table-in-magento-2-0\/\">Create New Database Table<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/webkul.com\/blog\/setup-script-files-magento2\/\">Setup Script Files<\/a><\/p>\n\n\n\n<p>Folder Structure till now,<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"218\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089-1200x218.png\" alt=\"Selection_089\" class=\"wp-image-390516\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089-1200x218.png 1200w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089-300x54.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089-250x45.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089-768x139.png 768w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_089.png 1412w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" loading=\"lazy\" \/><\/figure>\n\n\n\n<p>Next Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/magento-development-04-model-resource-model-and-collection\/\">Magento 2 Development 07: Model, Resource Model and Collection<\/a><\/p>\n\n\n\n<p>Previous Blog -&gt; <a href=\"https:\/\/webkul.com\/blog\/magento-development-02-route-management-and-controllers\/\">Magento 2 Routing<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before developing the frontend part of the module, let&#8217;s create some tables. It&#8217;s a good idea to create the tables beforehand. Because it helps us visualize the working of the module, which helps us in developing the module step by step. We will be developing a simple blog manager module so we need a table <a href=\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":201,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121,15559],"tags":[2460],"class_list":["post-282286","post","type-post","status-publish","format-standard","hentry","category-magento-2","category-wix","tag-magento-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Database Tables in Magento 2 - Webkul Blog<\/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:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Database Tables in Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Before developing the frontend part of the module, let&#8217;s create some tables. It&#8217;s a good idea to create the tables beforehand. Because it helps us visualize the working of the module, which helps us in developing the module step by step. We will be developing a simple blog manager module so we need a table [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-06T08:50:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-01T09:16:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\" \/>\n<meta name=\"author\" content=\"Sanjay Chouhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sanjay Chouhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\"},\"author\":{\"name\":\"Sanjay Chouhan\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\"},\"headline\":\"Create Database Tables in Magento 2\",\"datePublished\":\"2021-02-06T08:50:04+00:00\",\"dateModified\":\"2024-08-01T09:16:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\"},\"wordCount\":585,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\",\"keywords\":[\"Magento 2\"],\"articleSection\":[\"Magento 2\",\"wix\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\",\"name\":\"Create Database Tables in Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\",\"datePublished\":\"2021-02-06T08:50:04+00:00\",\"dateModified\":\"2024-08-01T09:16:17+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png\",\"width\":1128,\"height\":235,\"caption\":\"Selection_087\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Database Tables in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462\",\"name\":\"Sanjay Chouhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Sanjay Chouhan\"},\"sameAs\":[\"https:\/\/www.instagram.com\/sanjaychouhansc\/\",\"https:\/\/in.linkedin.com\/in\/scchouhansanjay\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Database Tables in Magento 2 - Webkul Blog","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:\/\/webkul.com\/blog\/create-database-tables-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Create Database Tables in Magento 2 - Webkul Blog","og_description":"Before developing the frontend part of the module, let&#8217;s create some tables. It&#8217;s a good idea to create the tables beforehand. Because it helps us visualize the working of the module, which helps us in developing the module step by step. We will be developing a simple blog manager module so we need a table [...]","og_url":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2021-02-06T08:50:04+00:00","article_modified_time":"2024-08-01T09:16:17+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png","type":"","width":"","height":""}],"author":"Sanjay Chouhan","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Sanjay Chouhan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/"},"author":{"name":"Sanjay Chouhan","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462"},"headline":"Create Database Tables in Magento 2","datePublished":"2021-02-06T08:50:04+00:00","dateModified":"2024-08-01T09:16:17+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/"},"wordCount":585,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png","keywords":["Magento 2"],"articleSection":["Magento 2","wix"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/","url":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/","name":"Create Database Tables in Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png","datePublished":"2021-02-06T08:50:04+00:00","dateModified":"2024-08-01T09:16:17+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2023\/07\/Selection_087.png","width":1128,"height":235,"caption":"Selection_087"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/create-database-tables-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Database Tables in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/645580979f637b0e355deea21bd07462","name":"Sanjay Chouhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cd6ee19f99bd1fcafef819135529c952d7c875d06fedd9fd4c4eb0996bafc1bd?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Sanjay Chouhan"},"sameAs":["https:\/\/www.instagram.com\/sanjaychouhansc\/","https:\/\/in.linkedin.com\/in\/scchouhansanjay"],"url":"https:\/\/webkul.com\/blog\/author\/sanjay-chouhan180\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/201"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=282286"}],"version-history":[{"count":17,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282286\/revisions"}],"predecessor-version":[{"id":455755,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/282286\/revisions\/455755"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=282286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=282286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=282286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}