General error: 1005 Can't create table 'magento2.easylife_table' in magento
-
16-10-2019 - |
Question
I have creating a table through my package(Ics->easylife->sql->install-0.0.1.php) file, but it's returning error.
can anyone tell me where I went wrong?
my code is
<?php
$installer = $this;
$installer->startSetup();
$table = $installer->getConnection()
->newTable($installer->getTable('easylife/easylife_table'))
->addColumn('easylife_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
'identity' => true,
'unsigned' => true,
'nullable' => false,
'primary' => true,
), 'EasyLife ID')
->addColumn('nom', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( ), 'Number')
->addColumn('prenom', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( ), 'Pre Number')
->addColumn('telephone', Varien_Db_Ddl_Table::TYPE_TEXT, '64k', array( ), 'Telephone Number')
->addForeignKey($installer->getFkName('easylife/easylife_table', 'easylife_id', 'easylife/easylife_table', 'easylife_id'),
'easylife_id', $installer->getTable('easylife/easylife_table'), 'easylife_id',
Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)
->setComment('Easy Life Table');
$installer->getConnection()->createTable($table);
$installer->endSetup();
thanks in advance.
Solution
Most probably it's the foreign key you are trying to add.
From what I see, you try to add a foreign key to the same field in the same table. That won'y work.
Either drop the addForeignKey
or reference an other table.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange