1

I have created an installschema for my custom table to be created.

<?php
namespace Vendor\Module\Setup;

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

class InstallSchema implements InstallSchemaInterface
{

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    $installer = $setup;
    $installer->startSetup();
     /**
     * Create new table 'my_table1'
     */
    $table = $installer->getConnection()
        ->newTable($installer->getTable('my_table1'))
        ->addColumn(
            'id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
            'ID'
        )
        ->addColumn(
            'product_id',
            \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
            null,
            ['unsigned' => true, 'nullable' => false, 'default' => '0'],
            'Product ID'
        )
        ->setComment('My new table');
    $installer->getConnection()->createTable($table);
    $installer->endSetup();
   }
}

And I gave setup:upgrade, but Im not able to see my custom table in the database. Where is my code wrong?

5
  • got any error while run command? Jul 20, 2016 at 7:14
  • no... php bin/magento setup:upgrade ran completely, my module is enabled
    – Sushivam
    Jul 20, 2016 at 7:15
  • I get 'My new table' as a comment in my debug.log...but no table in backend !!!
    – Sushivam
    Jul 20, 2016 at 7:16
  • Do you mean no table in database Jul 20, 2016 at 7:17
  • Yes no table in my DB
    – Sushivam
    Jul 20, 2016 at 7:18

1 Answer 1

1

Go to the database module_setup table

Check their is your setup with your setup_version and schema_vesrion

Delete that row and re run below command:

php bin/magento setup:upgrade
2
  • My module in bakend: Vendor_Module has schema and dataversion as 2.2.0.. u mean i have to delete that row and rerun?
    – Sushivam
    Jul 20, 2016 at 7:23
  • Yes you need to delete that row and rerun command Jul 20, 2016 at 7:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.