2012-05-08 105 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 –