Magento eav object configuration error - cannot create table

I'm trying to set up a custom object in Magento 1.7.0.0, following Alan storms an article about it , but with this simple installation script, he tells me that "Unable to create table: eavblog_posts".

My installation script is deadsimple and looks like this:

<?php $installer = $this; $installer->addEntityType('complexworld_eavblogpost', Array( 'entity_model'=>'complexworld/eavblogpost', 'attribute_model'=>'', 'table'=>'complexworld/eavblogpost', 'increment_model'=>'',eav/entity_increment_numeric 'increment_per_store'=>'0' )); $installer->createEntityTables( $this->getTable('complexworld/eavblogpost') ); 

How can I make my script installation work? Is this a known magento bug?

+4
source share
2 answers

First of all, this line is incorrect:

 'increment_model'=>'',eav/entity_increment_numeric 

It must be inside quotation marks.

Could not detect some errors in the latest installer.

Log in to your database using phpMyAdmin or similar, and check if any of the tables exist. If they do, delete them. Also delete the module entry in the core_resource file.

Try again.

Then there is a step that I cannot remember from my head (useful, I know, but I will try to remember it tonight and edit this).

After creating the tables, if you look at the assignment of foreign keys for type tables (int, text char, etc.), you will notice that the entity_id field is looking for eav_entity.entity_id. This needs to be changed in the eavblogpost_entity table.

You may also notice that the eavblogpost_entity.entity_id field is INT (11) when all foreign key references are INT (10). Change the eavblogpost_entity.entity_id field to INT (10) manually.

The only way around this is to override the createEntityTables () function with the one that works, or create all the tables manually. Here is a good resource to help you through this part of http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/

Worry with all of this when you go, and I'm sure you will stumble upon a step that you must take that I forgot. Sorry!

+1
source

In my case, the problem was caused by an error with the createEntityTables() method in Magento 1.7 / 1.12

In response to this error report , the Magento team recommends commenting on line 417 from lib / Varien / Db / Adapter / Pdo / Mysql.php:

 $this->_checkDdlTransaction($sql); 

Instead, I would recommend advice in a post by Zachary Schuessler and either

1) copying the createEntityTables() method to your own file (Your / Module / Model / Resource / Setup.php) and commenting on transaction methods ...

or

2) writing an abstract query to save transactions:

 // Example of MySQL API /** * Create table array('catalog/product', 'decimal') */ $table = $installer->getConnection() ->newTable($installer->getTable(array('catalog/product', 'decimal'))) ->addColumn('value_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( 'identity' => true, 'nullable' => false, 'primary' => true, ), 'Value ID') ->addColumn(... 
+5
source

Source: https://habr.com/ru/post/1411216/


All Articles