skip to Main Content

I have used setup to create table but script is not creating the table. I have also removed the entry from setup_module table but still, it didn’t work. Ive tried migration to declarative schema using bin/magento setup:install --convert-old-scripts=1 since its a Magento 2.3 installation, but the original script needs to work first.

magento-path/app/code/Folder/CustomModule/Setup/InstallSchema.php

<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace FolderCustomModuleSetup;
use MagentoFrameworkSetupInstallSchemaInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupSchemaSetupInterface;

/**
 * @codeCoverageIgnore
 */
class InstallSchema implements InstallSchemaInterface
{
    /**
    * {@inheritdoc}
    * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
    */
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
          /**
          * Create table 'shop_ocxe'
          */
          $setup->startSetup();

          $table = $setup->getConnection()
              ->newTable($setup->getTable('shop_ocxe'))
              ->addColumn(
                  'id',
                  MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
                  null,
                  ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                  'Shop ID'
              )
              ->addColumn(
                  'url',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  ['nullable' => false],
                  'Url'
              )
              ->addColumn(
                  'name',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  ['nullable' => false],
                  'Name'
              )
              ->addColumn(
                  'phrase',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  [],
                  'Phrase'
              )
              ->addColumn(
                  'logo',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  [],
                  'Logo'
              )
              ->addColumn(
                  'banner',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  [],
                  'Banner'
              )
              ->addColumn(
                  'author',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  ['nullable' => false],
                  'Author'
              )
              ->addColumn(
                  'author_photo',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  255,
                  ['nullable' => false],
                    'Author Photo'
              )
              ->addColumn(
                  'desc',
                  MagentoFrameworkDBDdlTable::TYPE_TEXT,
                  '64k',
                  [],
                  'Desc'
              )
              ->addColumn(
                  'status',
                  MagentoFrameworkDBDdlTable::TYPE_SMALLINT,
                  null,
                  ['nullable' => false, 'default' => 1],
                  'Status'
              )
              ->addColumn(
                  'created_at',
                  MagentoFrameworkDBDdlTable::TYPE_TIMESTAMP,
                  null,
                  ['nullable' => false, 'default' => MagentoFrameworkDBDdlTable::TIMESTAMP_INIT],
                  'Created At'
              )->addColumn(
                  'updated_at',
                  MagentoFrameworkDBDdlTable::TYPE_TIMESTAMP,
                  null,
                  ['nullable' => false, 'default' => MagentoFrameworkDBDdlTable::TIMESTAMP_INIT_UPDATE],
                  'Updated At'
              )->setComment("Shop Table");
          $setup->getConnection()->createTable($table);

          $setup->endSetup();
      }
}

2

Answers


  1. Chosen as BEST ANSWER

    Updating from the scripts to declarative schema worked for me. For anyone using Magento 2.3 and above it seems to be a must.

    Table Scheme Example:

    <table name="catalog_product_entity_datetime" resource="default" engine="innodb"
               comment="Catalog Product Datetime Attribute Backend Table">
        <column xsi:type="int" name="value_id" padding="11" unsigned="false" nullable="false" identity="true" comment="Value ID"/>
        <column xsi:type="smallint" name="attribute_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Attribute ID"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="false" identity="false" default="0" comment="Store ID"/>
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="false" default="0" comment="Entity ID"/>
        <column xsi:type="datetime" name="value" on_update="false" nullable="true" comment="Value"/>
        <constraint xsi:type="primary" referenceId="PRIMARY">
            <column name="value_id"/>
        </constraint>
        <constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_DTIME_ATTR_ID_EAV_ATTR_ATTR_ID" table="catalog_product_entity_datetime" column="attribute_id" referenceTable="eav_attribute" referenceColumn="attribute_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="CAT_PRD_ENTT_DTIME_ENTT_ID_CAT_PRD_ENTT_ENTT_ID" table="catalog_product_entity_datetime" column="entity_id" referenceTable="catalog_product_entity" referenceColumn="entity_id" onDelete="CASCADE"/>
        <constraint xsi:type="foreign" referenceId="CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID_STORE_STORE_ID" table="catalog_product_entity_datetime" column="store_id" referenceTable="store" referenceColumn="store_id" onDelete="CASCADE"/>
        <constraint xsi:type="unique" referenceId="CATALOG_PRODUCT_ENTITY_DATETIME_ENTITY_ID_ATTRIBUTE_ID_STORE_ID">
            <column name="entity_id"/>
            <column name="attribute_id"/>
            <column name="store_id"/>
        </constraint>
        <index referenceId="CATALOG_PRODUCT_ENTITY_DATETIME_ATTRIBUTE_ID" indexType="btree">
            <column name="attribute_id"/>
        </index>
        <index referenceId="CATALOG_PRODUCT_ENTITY_DATETIME_STORE_ID" indexType="btree">
            <column name="store_id"/>
        </index>
    </table>
    

    See more: Magento docs


  2. Try below steps:

     1. delete Jk_Ocxe entry from setup_module table .
     2. php bin/magento setup:upgrade
    

    I have tried and table is creating on my system.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search