I have an InstallSchema.php that just does not create the necessary table in the database. The code of the schema is as fallows :


namespace MyVendor\Helpdesk\Setup;

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

*   @codeCoverageIgnore
class InstallSchema implements InstallSchemaInterface
    public function install(SchemaSetupInterface    $setup, 
                            ModuleContextInterface  $context)
        $installer = $setup;
        $table = $installer->getConnection()
                                    ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                                    'Ticket Id'
                                    ['unsigned' =>  true],
                                    'Customer Id'
                                    ['nullable' =>  false],
                                    ['nullable' =>  false],
                                    ['nullable' =>  false],
                                    'Created At'
                                    ['nullable' =>  false],
                                    $installer->getIdxName('myvendor_helpdesk_ticket',  ['customer_id']),
                                    $installer->getFkName('myvendor_helpdesk_ticket', 'customer_id', 'customer_entity', 'entity_id'),
                            ->setComment('myvendor  Helpdesk Ticket');

I've run the fallowing commands:

php bin/magento setup:upgrade
php bin/magento setup:db-schema:upgrade

No errors were given, yet, when i get to my page I receive the fallowing error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.myvendor_helpdesk_ticket' doesn't exist

Please, help.

  • Did you define ‘myvendor_helpdesk_ticket’ anywhere? it may just be failing on the installer->getTable().
    – dbcn
    Feb 17 '16 at 14:26
  • what do u mean by define ? can you please provide a small example Feb 17 '16 at 14:35
  • I did create a ResourceModel, where I do app/code/MyVendor/Helpdesk/Model/ResourceModel/Ticket.php: $this->_init('myvendor_helpdesk_ticket', 'ticket_id'); If that is defining it... Everywhere else where I have the 'myvendor_helpdesk_ticket' string is in the code I've posted Feb 17 '16 at 14:38
  • i replaced "->newTable($installer->getTable('myvendor_helpdesk_ticket'))" with "->newTable('myvendor_helpdesk_ticket')" ... still nothing Feb 17 '16 at 14:44
  • 3
    try deleting from the table setup_module the record with module = 'MyVendor_Helpdesk'
    – Marius
    Feb 17 '16 at 14:53

The installer won't run again if it was already executed.
Removing the record from setup_module with module = 'MyVendor_Helpdesk' should make it run again.

  • Awesome Marius it is worked for me.
    – Naveenbos
    Jul 18 '16 at 12:55
  • And then php bin/magento setup:db-schema:upgrade worked for me
    – KTM
    May 7 '20 at 8:26
  • Thanks @Marius it works for me. May 12 '20 at 10:24
  • You should also ensure the namespace is correct in Setup/InstallSchema.php Jun 5 '20 at 1:36

please try the following code.

delete from setup_module where  module ='module_name';
sudo bin/magento setup:upgrade
sudo bin/magento setup:di:compile
sudo bin/magento cache:clean

if you get any permissions errors on var folder.

sudo chmod -R 777 var/*

Something i often do is drop the table if exists on InstallSchema.php:

public function install(SchemaSetupInterface $setup, ModuleContextInterface $context){
    // Drop table for development purpose
    $setup->getConnection()->dropTable($setup->getTable('my_custom_table')); ...

After this do:

  1. Access your DB
  2. Run the following command: DELETE FROM setup_module WHERE module ='module_name';
  3. Exit your DB
  4. In your Magento Root Folder execute: php bin/magento setup:db-schema:upgrade
  5. Check if everything is ok in your custom table.

just go to magento database and first delete the row from the setup_module table matching the name of your module that it should then run the InstallSchema again - #php -f bin/magento setup:upgrade

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.