1

I know there are many questions like this but after two days I am still unable to get the install method to build my database table in my module.

/app/code/me/HelloWorld/Setup/InstallSchema.php

namespace Me\HelloWorld\Setup;

use \Magento\Framework\Setup\InstallSchemaInterface;
use \Magento\Framework\Setup\ModuleContextInterface;
use \Magento\Framework\Setup\SchemaSetupInterface;
use \Magento\Framework\DB\Dbl\Table;


/**
 * Class InstallSchema
 *
 * @package Me\HelloWorld\Setup
 */
class InstallSchema implements InstallSchemaInterface {

/**
 * Install Posts table
 *
 * @param SchemaSetupInterface $setup
 * @param ModuleContextInterface $context
 */
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
    $setup->startSetup();

    $tableName = $setup->getTable("me_blog_post");

    if ($setup->getConnection()->isTableExists($tableName) != true) {
        $table = $setup->getConnection()
            ->newTable($tableName)
            ->addColumn(
                'post_id',
                Table::TYPE_INTEGER,
                null,
                [
                    'identity' => true,
                    'unsigned' => true,
                    'nullable' => false,
                    'primary' => true
                ],
                'ID'
            )
            ->addColumn(
                'title',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false],
                'Title'
            )
            ->addColumn(
                'content',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false],
                'Content'
            )
            ->addColumn(
                'created_at',
                Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => Table::TIMESTAMP_INIT],
                'Created At'
            );
        $setup->getConnection()->createTable($table);
    }

    $setup->endSetup();
}

}

I have:

cleared cache, deleted record from setup_modules in DB and reinstalled about 20 times, run bin/magento setup:di:compile, chmod 777 -R var/

And pretty much everything else anyone has suggested on here.

The most frustrating thing is the complete lack of error feedback in the "sudo bin/magento setup:upgrade" command.

So...

Can anyone see any errors in the code? Is there any way I can get some feedback on the "InstallSchema.php"

  • Is it a new module or a module version update? – PY Yick Oct 12 '17 at 4: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.