I have upgraded my Magento version from 2.2.7 to 2.3.2. I am working on a module where I have to create a table and insert some sample data.

As per the new conventions introduced in Magento 2.3.x, I created the table using app/code/[Packagename]/[Modulename]/etc/db_schema.xml. The table has been created successfully.

Now, I am trying to add data to the table using the patch file app/code/[Packagename]/[Modulename]/Setup/Patch/Data/InsertTemplates.php

The apply() function code is as follows:

public function apply()
    $data = array();
    $data[0]['template_name'] = __('Default Template 1');
    $data[0]['style_color'] = '#DC8C71';
    $data[0]['text_color'] = '#949392';
    $data[0]['caption'] = __('Gift Card');

    $data[1]['template_name'] = __('Default Template 2');
    $data[1]['style_color'] = '#DC8C71';
    $data[1]['text_color'] = '#636363';
    $data[1]['caption'] = __('Gift Card');

When I run the following commands:

php bin/magento setup:db-declaration:generate-whitelist --module-name=[Packagename]_[Modulename]

php bin/magento s:up

Both commands are running successfully, but the data is not being inserted into the table.

Can anyone help me understand, what can be the problem.


First of all, check whether you are using the correct Packagename and Modulename when running the command:

php bin/magento setup:db-declaration:generate-whitelist --module-name=[Packagename]_[Modulename]

Next, Magento uses the table patch_list to keep the patch version's history to prevent a re-run of the patch code.

Please check whether there is already an entry of your patch in the patch_list table.

I hope it give some clue.

Bonus: The command

php bin/magento setup:db-declaration:generate-whitelist --module-name=[Packagename]_[Modulename]

is not required when you install new data using a patch.

This command is only required when there is any database schema changed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.