I'm trying to add a custom table for a module. The following code sits the Setup folder of my module:


namespace tivol\storeAvailability\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;

class InstallSchema implements InstallSchemaInterface
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    $installer = $setup;

    // Get tivol_storeavailability table
    $tableName = $installer->getTable('tivol_storeavailability');
    // Check if the table already exists
    if ($installer->getConnection()->isTableExists($tableName) != true) {
        // Create tivol_storeavailability table
        $table = $installer->getConnection()
                            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                            ['default' => null, 'nullable' => false],
                            ['default' => null, 'nullable' => false],
            ->setComment('News Table')
            ->setOption('type', 'InnoDB')
            ->setOption('charset', 'utf8');


when I run it I get the following error on the frontend:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.tivol_storeavailability' doesn't exist, query was: SELECT main_table.* FROM tivol_storeavailability AS main_table

Any ideas as to why the table is not being created

  • you have to first delete your module entry from setup_module table and try again. – Rakesh Jesadiya Aug 22 '16 at 9:02
  • you are inserting $installer->getTable('tivol_storeavailability') inside of isTableExist, try changing $tableName to $tableName = 'tivol_storeavailability'; – belfort1 Aug 22 '16 at 9:02

Your Answer

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

Browse other questions tagged or ask your own question.