17

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

<?php

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;
        $installer->startSetup();
        $table = $installer->getConnection()
                            ->newTable($installer->getTable('myvendor_helpdesk_ticket'))
                            ->addColumn(
                                    'ticket_id',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                                    null,
                                    ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                                    'Ticket Id'
                            )
                            ->addColumn(
                                    'customer_id',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                                    null,
                                    ['unsigned' =>  true],
                                    'Customer Id'
                            )
                            ->addColumn(
                                    'title',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                                    null,
                                    ['nullable' =>  false],
                                    'Title'
                            )
                            ->addColumn(
                                    'severity',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                                    null,
                                    ['nullable' =>  false],
                                    'Severity'
                            )
                            ->addColumn(
                                    'created_at',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                                    null,
                                    ['nullable' =>  false],
                                    'Created At'
                            )
                            ->addColumn(
                                    'status',
                                    \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                                    null,
                                    ['nullable' =>  false],
                                    'Status'
                            )
                            ->addIndex(
                                    $installer->getIdxName('myvendor_helpdesk_ticket',  ['customer_id']),
                                    ['customer_id']
                            )
                            ->addForeignKey(
                                    $installer->getFkName('myvendor_helpdesk_ticket', 'customer_id', 'customer_entity', 'entity_id'),
                                    'customer_id',
                                    $installer->getTable('customer_entity'),
                                    'entity_id',
                                    \Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL
                            )
                            ->setComment('myvendor  Helpdesk Ticket');
        $installer->getConnection()->createTable($table);
        $installer->endSetup();
    }
}

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.

10
  • Did you define ‘myvendor_helpdesk_ticket’ anywhere? it may just be failing on the installer->getTable().
    – dbcn
    Feb 17, 2016 at 14:26
  • what do u mean by define ? can you please provide a small example Feb 17, 2016 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, 2016 at 14:38
  • i replaced "->newTable($installer->getTable('myvendor_helpdesk_ticket'))" with "->newTable('myvendor_helpdesk_ticket')" ... still nothing Feb 17, 2016 at 14:44
  • 3
    try deleting from the table setup_module the record with module = 'MyVendor_Helpdesk'
    – Marius
    Feb 17, 2016 at 14:53

4 Answers 4

39

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.

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

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/*
1

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

public function install(SchemaSetupInterface $setup, ModuleContextInterface $context){
    $setup->startSetup();
    // 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.
0

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.