magentoentity-attribute-value

Magento eav entity setup failing - Can't create table


I am trying to set up a custom entity in Magento 1.7.0.0, following alan storms article about it, but with this simple install script, it tells me that "Can't create table: eavblog_posts".

My install 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 get my install script working? Is this a known magento bug?


Solution

  • First of all, this line is wrong:

    'increment_model'=>'',eav/entity_increment_numeric
    

    It needs to be inside the quotes.

    Failing that there are some bugs in the installer functions of the latest version.

    Go into your database using phpMyAdmin or similar and check to see if any of the tables already exist. If they do, delete them. Also delete the module's record in core_resource.

    Try again.

    Then there's a step in here I cant remember off the top of my head (useful, I know, but I'll try and remember it tonight and edit this).

    Once the tables have been created, if you look at the foreign key assignments for the type tables (int, text char etc) you'll notice that the entity_id field is looking at eav_entity.entity_id. This needs to change to your eavblogpost_entity table.

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

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

    Mess around with all of these as you go and I'm sure you'll stumble across the step that you have to do that I've forgotten. Sorry!