How to fix the error "SQLSTATE[...] Base table or view not found..." in Magento 2?

Issue

The following fatal error may appear in your shop backend or frontend after installing the module in your Magento store:

SQLSTATE[...]: Base table or view not found...

This happens when the database migration scripts for our module were not executed.

Resolution

The triggering of the migration scripts may require multiple approaches. It depends on the Magento version and the setup which method will finally triggers the migration properly. We recommend to try the following approaches one by one until the error disappears:

  1. Try empty the Magento caches. You may want to clear the cache storage but also each indivual caches. Older Magento versions have issues with clearing the cache properly. If this does not solve the issue connecto to your server via FTP/SFTP and delete the complete contente of the folder "Cache".
  2. Delete the module's entry in the table setup_module. See below how to do that.

If none of the above solves the issue please get in contact with us.

Reset setup_module table

The setup_module table holds for each module an entry. The entry defines the current version installed. Resetting of the entry will trigger the database migration again. Our migration scripts are written in a way that they can be executed multiple times. Means a reset of this entry for our module will not cause an issue. However you should not reset the entries for all modules. This may cause a major data loss!

The reason why the above is required is located in how MySQL applies schema changes. MySQL executes those changes not within a database transaction and as such a failure will not rollback all changes. The entry within the setup_module table is written first. The schema changes are applied afterwards. As such in case of a database failure during the migration it can happen that not all changes have been applied even though the version has been changed. A failure of the database system during the migration is quite likely since schema changes are typically hard to process for a database.

Follow the steps below to reset the version of our module:

  1. Login to your database with an appropriate tool such as phpMyAdmin or the MySQL Workbench.
  2. Search the table setup_module.
  3. Remove the entry which is related to our module. The entry will have the format <Payment_Service_Provider>cw_setup.
  4. Run this command over SSH: setup:upgrade.