1

I had the same issue as many people had already Install schema not creating table

I searched and I found a solution but even more confused when the solution is work on setup_module table which is not found in my database.

I am new to magento so assist me if I have done any basics wrong

<?php
class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
{

public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
{
    $installer = $setup;
    $installer->startSetup();
    if (!$installer->tableExists('aravind_customerattribute_post')) {
        $table = $installer->getConnection()->newTable(
            $installer->getTable('aravind_customerattribute_post')
        )
            ->addColumn(
                'post_id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                [
                    'identity' => true,
                    'nullable' => false,
                    'primary'  => true,
                    'unsigned' => true,
                ],
                'Post ID'
            )
            ->addColumn(
                'name',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                ['nullable => false'],
                'Post Name'
            )
            ->addColumn(
                'url_key',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'Post URL Key'
            )
            ->addColumn(
                'post_content',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                '64k',
                [],
                'Post Post Content'
            )
            ->addColumn(
                'tags',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'Post Tags'
            )
            ->addColumn(
                'status',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                1,
                [],
                'Post Status'
            )
            ->addColumn(
                'featured_image',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'Post Featured Image'
            )
            ->addColumn(
                    'created_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                    'Created At'
            )->addColumn(
                'updated_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                'Updated At')
            ->setComment('Post Table');
        $installer->getConnection()->createTable($table);

        $installer->getConnection()->addIndex(
            $installer->getTable('aravind_customerattribute_post'),
            $setup->getIdxName(
                $installer->getTable('aravind_customerattribute_post'),
                ['name','url_key','post_content','tags','featured_image'],
                \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
            ),
            ['name','url_key','post_content','tags','featured_image'],
            \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_FULLTEXT
        );
    }
    $installer->endSetup();
}
}
?>


php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy

The file is in /var/www/html/magento2/app/code/Aravind/CustomerAttribute/Setup/InstallSchema.php

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Aravind_CustomerAttribute" setup_version="2.1.0" />
</config>
6
  • can u please add you code in question?
    – Abdul
    Jan 8 '18 at 6:14
  • Added code as per your request
    – Abel
    Jan 8 '18 at 6:24
  • And /var/www/html/magento2/app/code/Aravind/CustomerAttribute/etc/module.xml file? have u added any setup ver this file?
    – Abdul
    Jan 8 '18 at 6:29
  • Included module.xml. Is the setup_module table created on run time or is that table exist by default?
    – Abel
    Jan 8 '18 at 6:35
  • Your create new table code is fine, but could you check if you missed defining namespace namespace Aravind\CustomerAttribute\Setup; in InstallSchema.php?
    – Quan Le
    Jan 8 '18 at 7:01

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.