M
M
Maxim Romashko2020-05-05 09:46:56
Magento
Maxim Romashko, 2020-05-05 09:46:56

How to make installSchema work?

Hello, I recently started to deal with this CMS, but I ran into a problem that I can’t correctly make an installation script that will add a table to the database

<?php
namespace md5inj\MyTest_Custom\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)
  {
      
    $newsTableName = $setup->getTable('rsgitech_news');

    if($setup->getConnection()->isTableExists($newsTableName) != true) {

      $newsTable = $setup->getConnection()
          ->newTable($newsTableName)
          ->addColumn(
              'news_id',
              \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
              null,
              ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
              'News ID'
          )
          ->addColumn(
              'title',
              \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
              255,
              ['nullable' => false, 'default' => ''],
                'Title'
          )
          ->addColumn(
              'description',
              \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
              null,
              ['nullable' => false, 'default' => ''],
                'Description'
          )
          ->addColumn(
              'status',
              \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
              null,
              ['nullable' => false, 'unsigned' => true],
                'Status'
          )
          ->addColumn(
              'created_at',
              \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
              null,
              ['nullable' => false],
                'Created At'
          )
          ->addColumn(
              'updated_at',
              \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
              null,
              ['nullable' => false],
                'Updated At'
          )
          ->addIndex(
            $setup->getIdxName('rsgitech_news', ['title']),
            ['title']
          )
          ->setComment("News Table");

      $setup->getConnection()->createTable($newsTable);
    }
  }
}
?>

This file is located along the path app/code/md5inj/MyTest_Custom/Setup/InstallSchema.php.
Procedure:
1. Saved the file
2. Deleted the entry with my module from the setup_module table
3. Did sudo php bin/magento setup:db-schema:upgrade
Everything seems to be ok, but even if I write complete nonsense in the install function, there is no error is thrown out, tell me please, what is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Smetana, 2020-05-25
@konstantin_s90

Module activated?
Have you tried php bin/magento module:status
php bin/magento setup:upgrade?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question