Reputation: 1723
I am using magento 1.4.2.0 and i need to add a new table to my magento database,It is for some of my custom cms pages where i need to add data to database and need to fetch that data and show it in the cms pages.Please explain me step by step as i am very new to magento.
Upvotes: 1
Views: 5861
Reputation: 1
class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
{
public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$table = $setup->getConnection()
->newTable($setup->getTable('magento_pincode_pincode'))
->addColumn(
'pincode_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
[
'identity' => true,
'nullable' => false,
'primary' => true,
'unsigned' => true
],
'ID'
)->addColumn(
'pincode',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['nullable' => false],
'Pincode'
)->addColumn(
'status',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['nullable' => false],
'Status'
)->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');
$setup->getConnection()->createTable($table);
$setup->endSetup();
}
}
Upvotes: 0
Reputation: 21
Create table using magento module write following code in sql folder mysql4-install-1.0.0.php file.
$installer = $this;
$table = $installer->getConnection()->newTable($installer->getTable(''))
->addColumn('news_id',Varien_Db_Dbl_Table::INTEGER_TYPE,null,array('unsigned'=>true,'identity'=>true,'nullable'=>false,'primary'=>true),'Entity Id')
->addColumn('title',Varien_Db_Dbl_Table::TYPE_TEXT,255,array('nullable'=>true),'Title')
->addColumn('author',Varien_Db_Dbl_Table::TYPE_TEXT,63,array('nullable'=>true,'default'=>'null'),'Author')
->addColumn('content',Varien_Db_Dbl_Table::TYPE_TEXT,'2M',array('nullable'=>true,'default'=>'null'),'Content')
->addColumn('image',Varien_Db_Dbl_Table::TYPE_TEXT,null,array('nullable'=>true,'default'=>'null'),'News Image Media Path')
->addColumn('publised_at',Varien_Db_Dbl_Table::TYPE_DATE,null,array('nullable'=>true,'default'=>'null'),'Published Date')
->addColumn('created_at',Varien_Db_Dbl_Table::TYPE_TIMESTAMP,null,array('nullable'=>true,'default'=>'null'),'Creation Time')
->addIndex($installer->getIdxName($installer->getTable(''),array('publised_at'),Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX),array('publised_at'),array('type'=>Varien_Db_Adapter_Interface::INDEX_TYPE_INDEX))->SetComment('News Item');
$installer->getConnection->createTable($table);
Upvotes: 0
Reputation: 8587
you have to use a setup file in your module: check out Alan Storm's comprehensive post
Upvotes: 2