2012-05-08 109 views
4

我想在Magento 1.7.0.0中设置一个自定义实体,跟在alan storms article about it之后,但是通过这个简单的安装脚本,它告诉我“无法创建表: eavblog_posts”。Magento eav实体设置失败 - 无法创建表

我的安装脚本是deadsimple,看起来像这样:

<?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') 
); 

我怎样才能让我的安装脚本的工作?这是一个已知的magento错误吗?

回答

1

首先,这条线是错误的:

'increment_model'=>'',eav/entity_increment_numeric 

它需要引号内。

如果最新版本的安装程序功能中存在一些错误,

使用phpMyAdmin或类似工具进入您的数据库,并检查是否有任何表已存在。如果他们这样做,删除它们。还要删除core_resource中的模块记录。

再试一次。

然后在这里有一个步骤,我不能记住我的头顶(有用,我知道,但我会尽量记住它,并编辑这个)。

创建表后,如果您查看类型表的外键分配(int,text char等),您会注意到entity_id字段正在查看eav_entity.entity_id。这需要更改为您的eavblogpost_entity表。

当所有外键引用都是INT(10)时,您可能还会注意到eavblogpost_entity.entity_id字段为INT(11)。手动将eavblogpost_entity.entity_id字段更改为INT(10)。

解决所有这些问题的唯一方法是使用一个可用的函数覆盖createEntityTables()函数,或手动创建所有表。这是一个很好的资源,可以帮助你完成整个过程http://inchoo.net/ecommerce/magento/creating-an-eav-based-models-in-magento/

随着所有这些事情的发展,我相信你会绊倒你必须做的那一步,我忘记了。抱歉!

+0

对不起,我认为计划的评论是不明确的。代码如下'increment_model'=>'','increment_per_store'=>'0',我会尽力为您提供答案,非常感谢 –

5

在我的情况下,这个问题是由于一个错误与在Magento的createEntityTables()方法1.7/1.12

their answer to this bug report,Magento的团队建议注释掉线417的lib /瓦瑞恩/ DB /适配器/ PDO/Mysql.php:

$this->_checkDdlTransaction($sql); 

相反,我会建议以下the advice in Zachary Schuessler's post,要么

1)复制createEntityTables()方法来自己的文件(你的/模块/型号/资源/ Setup.php)和Co为了保持交易mmenting出来的交易方式...

2)写一个抽象查询:

// 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(... 
+0

Afaics,绝对没有理由选择#2。 #1罚款#2不给你交易要么... :( – jmlnik

+0

代码是不同的1.9,我不得不删除eav_entity_type中的FK –