0

Installing schema... Upgrading schema... SQLSTATE[42S02]: Base table or view not found: 1146 Table 'st_m2_225_21082018.sentence_sentence' doesn't exist, query was: DESCRIBE SENTENCE_SENTENCE

<?php
    namespace Vendor\Module\Setup;

    use Magento\Framework\Setup\UpgradeSchemaInterface;
    use Magento\Framework\Setup\ModuleContextInterface;
    use Magento\Framework\Setup\SchemaSetupInterface;

    class UpgradeSchema implements  UpgradeSchemaInterface
    {
        public function upgrade(SchemaSetupInterface $setup,
            ModuleContextInterface $context){
            $setup->startSetup();


            if (version_compare($context->getVersion(), '1.9.1') < 0) {

                // Get module table
                $tableName = $setup->getTable('sentence');

                // Check if the table already exists
                if ($setup->getConnection()->isTableExists($tableName) == true) {
                    // Declare data
                    $columns = [
                    'sentence' => [
                    'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    'nullable' => false,
                    'comment' => 'sentence',
                    ],
                    ];

                    $connection = $setup->getConnection();
                    foreach ($columns as $name => $definition) {
                        $connection->addColumn($tableName, $name, $definition);
                    }
                    $connection->addIndex(
                        $setup->getIdxName(
                            $tableName,
                            ['sentence'],
                            \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
                        ),
                        'sentence',
                        ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
                    );

                }
            }

            $setup->endSetup();
        }
    }
    ?>
  • 1
    I just checked your script on my Magento2 instance, it works fine. What is the 'table_prefix' in your env.php? – bachlee89 Dec 21 '18 at 7:54
  • it's blank @Lee – Rutvee Sojitra Dec 21 '18 at 7:57
  • 1
    you can try this. $installer = $setup; $installer->startSetup(); $tableName = $installer->getConnection()->newTable( $installer->getTable('sentence') ) – Pritam Info 24 Dec 21 '18 at 8:04

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.