I am creating a custom Module, in that I created a custom table and patch data. The patch data for inserting data into that table. Now the issue is, the custom table was created through declarative schema, when I am installing a module, the patch data get executed before table creation, so it is throwing errors. I would like to add table schema as a dependency in setup patch data using public static function getDependencies() function.

Is this possible to add table schema as a dependency in setup patch data? If not please suggest me a better solution to fix this.

Note: I don't want to use setup scripts (Install/Upgrade scripts) to create tables. I just want to achieve this with declarative schema.

Thanks in advance!

1 Answer 1


would suggest checking at first whether a table exists in your patch (i.e $setup->getConnection()->isTableExists()) or not. if it doesn't exist first create the table then you may insert your data, you can take reference of the below file path if that helps: vendor/magento/module-catalog/Setup/Patch/Schema/EnableSegmentation.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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