Magento eav 实体设置失败 - 创建了一半表,其他表没有创建

发布于 2025-01-05 08:49:02 字数 905 浏览 0 评论 0原文

我正在尝试设置一个自定义实体,按照关于它的alanstorms文章,但是使用这个简单的安装脚本,它告诉我无法创建表:extend_categories_text。当我查看数据库时,我实际上可以看到下表:

extended_categories
extended_categories_datetime
extended_categories_decimal
extended_categories_int

我的安装脚本非常简单,如下所示:

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

如何让我的安装脚本工作?这是已知的 magento bug 吗?

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?

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

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

发布评论

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

评论(3

红玫瑰 2025-01-12 08:49:02

在我上一篇文章之后,我在同一个教程中取得了一些进展,但我仍然遇到了问题。最后,我看到这两篇文章,它们使我能够完成本教程:

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

最后一条指出我使用的Magento版本存在错误。

Mage_Eav_Model_Entity_Setup,第 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)

应为:

->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)

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)

油饼 2025-01-12 08:49:02

我在 1.7.0.0 上也遇到了同样的问题。
我发现问题出在 createEntityTables() 方法的事务(第 1359 行)中,但我不知道为什么......

所以我只是将整个 createEntityTables() 方法复制到我的安装脚本中(我不想弄乱了核心!),将 foreach 循环(第 1361 行)移出事务,一切正常!

至于为什么 beginTransaction() 可能会抛出异常,我不知道!

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!

此岸叶落 2025-01-12 08:49:02

我遇到了同样的问题。在我的情况下,我意识到尝试创建数据库表时发生的错误是: BLOB/TEXT 列“值”在没有键长度的键规范中使用

强制 Magento 呈现我的数据库的 SQL 语句可以接受,我必须修改 app/code/core/Mage/Eav/Model/Entity/Setup.php 文件大约第 1337 行(在 createEntityTables 方法内) 。替换以下行:

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

这样:

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

我用这张票来解决上述问题: BLOB/TEXT 列“值”在没有密钥长度的密钥规范中使用

如果这不能解决您的问题,我建议进入在createTable方法中的lib/Varien/Db/Adapter/Pdo/Mysql.php文件中,在return语句之前添加以下代码:

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

这样你就可以看到什么SQL您的数据库有问题,因此您可以在 SQL 客户端(即 phpMyAdmin)中尝试,这将为您提供有关问题所在的更具描述性的解释。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文