I'm following this tutorial to create a new table inside the database.
From the tutorial, I've followed till Step 4. I can verify that a the new module is created after running php bin/magento setup:upgrade
, but no table named greeting_message
is created for me.
I guess, The database here refers to the database I created while Installing Magento. I've seen all the tables of the database from phpmyadmin but there is no database named greeting_message
.
Where am I going Wrong?
InstallData.php
<?php
namespace Learning\GreetingMessage\Setup;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/**
* Install messages
*/
$data = [
['message' => 'Happy New Year'],
['message' => 'Marry Christams']
];
foreach ($data as $bind) {
$setup->getConnection()
->insertForce($setup->getTable('greeting_message'), $bind);
}
}
}
InstallSchema.php
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Learning\GreetingMessage\Setup;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
/**
* Create table 'greeting_message'
*/
$table = $setup->getConnection()
->newTable($setup->getTable('greeting_message'))
->addColumn(
'greeting_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
'Greeting ID'
)
->addColumn(
'message',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['nullable' => false, 'default' => ''],
'Message'
)->setComment("Greeting Message table");
$setup->getConnection()->createTable($table);
}
}