2

I am trying to set up a custom entity, following along alan storms article about it, but with this simple install script, it tells me that Can't create table: extended_categories_text. When i look in the database, i can actually see the following tables:

extended_categories
extended_categories_datetime
extended_categories_decimal
extended_categories_int

My install script is deadsimple and looks like this:

<?php
$installer = $this;

$installer->addEntityType('csvengine_extendedcategories',Array(
    'entity_model'          =>'csvengine/extendedcategories',
    'attribute_model'       =>'',
    'table'                 =>'csvengine/extendedcategories',
    'increment_model'       =>'eav/entity_increment_numeric',
    'increment_per_store'   =>'0'
));

$installer->createEntityTables(
    $this->getTable('csvengine/extendedcategories')
);

How can i get my install script working? Is this a known magento bug?

Jan Dragsbaek
  • 8,078
  • 2
  • 26
  • 46

3 Answers3

1

I had the same issue with 1.7.0.0. I found that the problem was in the transaction (line 1359) of the createEntityTables() method, but I don't know why...

So I just copied the whole createEntityTables() method to my install script ( I don't wanna mess with the core!), moved the foreach loop (line 1361) out of the transaction and everything worked fine!

As to why beginTransaction() could be throwing an exception, I have no idea!

Matt
  • 74,352
  • 26
  • 153
  • 180
  • 2
    It's because DDL routines cannot be rolled back in MySQL. The best method is to do as you mentioned on Alan's article: to extend the method and just comment out the startTransaction() and rollBack() lines. More info: http://zaclee.net/magento/custom-module-setup-createentitytables-method-fails – Zachary Schuessler Sep 24 '12 at 12:44
1

After my previous post, I got a little farther in the same tutorial, but I still ran into issues. Finally, I was lead to these two posts which allowed me to complete the tutorial:

http://www.magentocommerce.com/bug-tracking/issue/?issue=12336
http://www.magentocommerce.com/bug-tracking/issue/?issue=12126

The last one points out an error in the version of Magento I was using.

Mage_Eav_Model_Entity_Setup , Line 1341:

->addForeignKey($this->getFkName($eavTableName, 'entity_id', 'eav/entity', 'entity_id'), 'entity_id', $this->getTable('eav/entity'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)

Should be:

->addForeignKey($this->getFkName($eavTableName, 'entity_id', 'eav/entity', 'entity_id'), 'entity_id', $baseTableName, 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE)

Steven
  • 3,526
  • 3
  • 18
  • 28
  • 1
    It's usually preferrable to edit your original post with new information as opposed to posting again. Just FYI – RThomas May 15 '12 at 21:44
0

I encountered the same problem. In my situation I realized that the error occurring when trying to create the database table was: BLOB/TEXT column 'value' used in key specification without a key length

To force Magento to render SQL statements that my database could accept, I had to modify the app/code/core/Mage/Eav/Model/Entity/Setup.php file at approximately line 1337 (inside the createEntityTables method). Replacing the following lines:

        ->addIndex($this->getIdxName($eavTableName, array('attribute_id', 'value')),
            array('attribute_id', 'value'))
        ->addIndex($this->getIdxName($eavTableName, array('entity_type_id', 'value')),
            array('entity_type_id', 'value'))

With this:

        ->addIndex($this->getIdxName($eavTableName, array('attribute_id', 'value')),
            array('attribute_id', $type == 'text' ? array('name' => 'value', 'size' => 255) : 'value'))
        ->addIndex($this->getIdxName($eavTableName, array('entity_type_id', 'value')),
            array('entity_type_id', $type == 'text' ? array('name' => 'value', 'size' => 255) : 'value'))

I used this ticket to solve the above problem: BLOB/TEXT column 'value' used in key specification without a key length

If this doesn't solve your problem, I would suggest going into the lib/Varien/Db/Adapter/Pdo/Mysql.php file inside the createTable method and adding the following code just before the return statement:

    echo "<pre>SQL:\n$sql\n\n</pre>";

This way you can see what SQL your database is having issues with so you can try it in an SQL client (ie. phpMyAdmin) that will give you a more descriptive explanation of what's going wrong.

Community
  • 1
  • 1
Steven
  • 3,526
  • 3
  • 18
  • 28