带 EAV 的 Magento 自定义模块 - 无法创建文本表

发布于 2024-12-23 10:24:55 字数 547 浏览 1 评论 0 原文

我正在尝试使用 Magento 的 EAV 结构创建自定义模块,并一直使用本教程作为指南: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-7-advanced-orm-entity-attribute-value

一切似乎都正常除了我的安装脚本在尝试创建 _text 表时总是失败。它创建前 3 个 -entityname_datetime、entityname_int 和entityname_decimal,然后抛出异常:无法从核心资源设置模型创建表:entityname_text。

我尝试更改表名称,但在同一点失败。除了更改模型和实体名称之外,我的代码与教程中的内容完全一致。

有什么调试技巧吗?在核心资源设置模型中使用 Mage::log 似乎不起作用,尽管我无法理解为什么。

I'm trying to create a custom module using Magento's EAV structure and have been using this tutorial as a guide: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-7-advanced-orm-entity-attribute-value

Everything seems to be working except my install script is always failing on trying to create the _text table. It creates the first 3 - entityname_datetime, entityname_int and entityname_decimal and then throws the exception: Can't create table: entityname_text from the core resource setup model.

I've tried changing the table name but it fails at the same point. Except for changing the model and entity names, my code exactly mirrors that from the tutorial.

Any tips for debugging? Using Mage::log within the core resource setup model doesn't seem to be working, though I can't fathom why.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花辞树 2024-12-30 10:24:55

This is bug that was recently introduced to the Community Edition version of the product. It's been reported to the core team via their public-with-a-login bug tracker. For now I'd skip creating non-varchar text types and continue working your way through the tutorial. (not ideal, but as the tutorial suggests, you'll it's a rare use-case that calls for a scratch EAV model)

扶醉桌前 2024-12-30 10:24:55

更改表名称后,您是否尝试从模块的 core_resource 表中删除条目并清除缓存?顺便说一句,你用的是什么名字?

after changing table name have u tried removing entry from core_resource table of your module and clearing the cache? btw, what name you are using?

幸福不弃 2024-12-30 10:24:55

Magento 团队的解决方案 错误报告参考链接

class Namespace_Modulename_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
    public function createEntityTables($baseTableName, array $options = array())
    {
        ...

        /**
         * DDL operations cannot be executed within transaction so these lines are useless
         */
        //$connection->beginTransaction();
        try { 
            foreach ($tables as $tableName => $table) {
                $connection->createTable($table);
            }
            $connection->commit();
       } catch (Exception $e) {
           //$connection->rollBack();
           throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Can\'t create table: %s', $tableName));
       }
    }
}

solution by Magento Team bug report reference link

class Namespace_Modulename_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
{
    public function createEntityTables($baseTableName, array $options = array())
    {
        ...

        /**
         * DDL operations cannot be executed within transaction so these lines are useless
         */
        //$connection->beginTransaction();
        try { 
            foreach ($tables as $tableName => $table) {
                $connection->createTable($table);
            }
            $connection->commit();
       } catch (Exception $e) {
           //$connection->rollBack();
           throw Mage::exception('Mage_Eav', Mage::helper('eav')->__('Can\'t create table: %s', $tableName));
       }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文