{"id":944,"date":"2020-04-15T09:00:50","date_gmt":"2020-04-15T09:00:50","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/04\/15\/create-db-schema-whitelist-json-in-magento-2\/"},"modified":"2026-04-22T13:26:43","modified_gmt":"2026-04-22T07:56:43","slug":"create-db-schema-whitelist-json-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-db-schema-whitelist-json-in-magento-2\/","title":{"rendered":"How to Create db_schema_whitelist.json in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">With the release of\u00a0<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-3-release\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2.3<\/a>, the declarative schema was introduced to ease the installation and upgrade process.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Declarative Schema files declare what the database structure should be.\u00a0Magento (Adobe Commerce)determines the differences between the current table structure and what it should be.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>db_schema_whitelist.json<\/code>\u00a0file is a history of all tables, columns, and keys added with the declarative schema. It can be generated manually or\u00a0create a db_schema_whitelist.json in Magento 2\u00a0using the following method:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to create db_schema_whitelist.json in Magento 2:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Db_schema_whitelist file can be created automatically using the below command :<\/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=\"\">php bin\/magento setup:db-declaration:generate-whitelist --module-name=YourModule_Name<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the Modulename is not specified, then the default behaviour is to generate a whitelist for all the modules in a system. You can set options as \u2013<strong>module-name = all<\/strong>\u00a0for all the modules.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Module uses a declarative schema and uses module setup scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Declare table column using db_schema file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suppose you have two columns named Id and foo. When\u00a0<strong>setup:upgrade<\/strong>\u00a0runs, the table will be created. After that, you need to add one extra column named bar.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For eg., $table-&gt;addColumn(\u2018sales order\u2019,\u2019bar\u2019)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now run&nbsp;<strong>setup:upgrade<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now declarative schema is evaluated again and compared again with the existing database. Declarative schema realizes that new additional column is there.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Usually, it would remove the column from db_schema file and you need to also remove from the database.<br>But that is the wrong assumption, that\u2019s why db_shema_whitelist comes into place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To create db_schema_whitelist.json first you need to create&nbsp;<em><strong>db_schema.xml<\/strong><\/em>&nbsp;file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app\/code\/vendor\/Module\/etc\/db_schema.xml<\/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\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=\"vendor_module_example\" resource=\"default\" comment=\"My table\" charset=\"utf8\">\n        &lt;column name=\"id\" xsi:type=\"int\" padding=\"5\" unsigned=\"true\" identity=\"true\" nullable=\"false\">&lt;\/column>\n        &lt;column name=\"name\" xsi:type=\"varchar\" nullable=\"false\" length=\"124\">&lt;\/column>\n        &lt;column name=\"description\" xsi:type=\"text\" nullable=\"true\">&lt;\/column>\n        &lt;column name=\"is_enabled\" xsi:type=\"boolean\" nullable=\"false\" default=\"0\">&lt;\/column>\n        &lt;column name=\"weighing_factor\" xsi:type=\"decimal\" precision=\"5\" scale=\"4\">&lt;\/column>\n        &lt;column name=\"created_at\" xsi:type=\"timestamp\" default=\"CURRENT_TIMESTAMP\">&lt;\/column>\n        &lt;column name=\"updated_at\" xsi:type=\"timestamp\" default=\"CURRENT_TIMESTAMP\" on_update=\"true\">&lt;\/column>\n    &lt;\/table>\n&lt;\/schema><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Run the below command<\/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=\"\">php bin\/magento setup:db-declaration:generate-whitelist --module-name=Vendor_Module<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Check you etc folder where db_schema_whitelist.json is generated.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also refer to the&nbsp;<a href=\"https:\/\/developer.adobe.com\/commerce\/docs\/\" target=\"_blank\" rel=\"noreferrer noopener\">official document<\/a>&nbsp;for more details.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to share the solution with fellow Magento (Adobe Commerce) developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the release of\u00a0Magento 2.3, the declarative schema was introduced to ease the installation and upgrade process. Declarative Schema files declare what the database structure should be.\u00a0Magento (Adobe Commerce)determines the differences between the current table structure and what it should be. db_schema_whitelist.json\u00a0file is a history of all tables, columns, and keys added with the declarative [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-944","post","type-post","status-publish","format-standard","hentry","category-magento"],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/944","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=944"}],"version-history":[{"count":6,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/944\/revisions"}],"predecessor-version":[{"id":26340,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/944\/revisions\/26340"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}