4

The module is correctly enabled and it shows in the setup_module - and i can see him on front end with the route. But tables is not created in the database. I don't no whats wrong in it.

My installerschema.php:

<?php
namespace Inchoo\Helloworld\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;

class InstallSchema implements InstallSchemaInterface {

    public function install( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
        $installer = $setup;

        $installer->startSetup();

        /**
         * Create table 'posts'
         */
        $table = $installer->getConnection()->newTable(
            $installer->getTable( 'inchoo_blog_posts' )
        )->addColumn(
            'post_id',
            Table::TYPE_SMALLINT,
            null,
            [ 'identity' => true, 'nullable' => false, 'primary' => true ],
            'Post ID'
        )->addColumn(
            'title',
            Table::TYPE_TEXT,
            255,
            [ 'nullable' => false ],
            'Post Title'
        )->addColumn(
            'content',
            Table::TYPE_TEXT,
            '2M',
            [ ],
            'Post Content'
        )->setComment(
            'Blog Post Table'
        );

        $installer->getConnection()->createTable( $table );

        $installer->endSetup();
    }
}

Please help me.

  • Try deleting from the table setup_module the record with module = 'Inchoo_Helloworld'; – Krishna ijjada Nov 2 '16 at 7:44
3

compare your installschema: (you missed to inject \Framework\DB\Ddl\Table)

     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
 {
/**
 * Installs DB schema for a module
 *
 * @param SchemaSetupInterface $setup
 * @param ModuleContextInterface $context
 * @return void
 */
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    $installer = $setup;

    $installer->startSetup();

    if (!$installer->tableExists('table_name')) {
        $table = $installer->getConnection()
            ->newTable($installer->getTable('table_name'))
            ->addColumn(
                'id',
                Table::TYPE_INTEGER,
                10,
                ['identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true]
            )->addColumn(
                'store_id',
                 Table::TYPE_SMALLINT,
                 10, 
                 ['nullable' => false]
            )->addColumn(
                'title',
                 Table::TYPE_TEXT,
                 '2M', 
                 ['nullable' => false]
            )->addColumn(
                'description',
                 Table::TYPE_TEXT,
                 '2M', 
                 ['default' => ''], 
                 'Description'
            )->addColumn(
                'creation_time',
                 Table::TYPE_DATETIME,
                 null, 
                 ['nullable' => false], 'Creation Time'
            )->addColumn(
                'update_time', 
                Table::TYPE_DATETIME, 
                null, 
                ['nullable' => false], 
                'Update Time'
            )->setComment('table comments');        
     }

    $installer->getConnection()->createTable($table);
    $installer->endSetup();
}

}

| improve this answer | |

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.