magento 中的资源设置问题

发布于 2024-11-16 15:26:59 字数 4250 浏览 0 评论 0原文

提前对冗长的帖子表示歉意。

我正在关注 Alan Storm 关于 magento 开发的文章。我正在关注该系列中有关资源设置的第 6 部分。我在配置文件中创建了资源设置,并适当地放置了 Setup.php 文件。但是,如果我尝试刷新缓存或尝试访问 magento 的任何页面,我会收到一条错误消息:处理您的请求时出错。如果我从配置文件中删除设置部分,一切都会再次完美运行。这是我的文件: Config.xml 文件

<config>    
    <modules>
        <Foostor_Weblog>
            <version>0.1.0</version>
        </Foostor_Weblog>
    </modules>
    <frontend>
        <routers>
            <weblog>
                <use>standard</use>
                <args>
                    <module>Foostor_Weblog</module>
                    <frontName>weblog</frontName>
                </args>
            </weblog>
        </routers>
    </frontend> 
    <global>
        <models>
        <weblog>
            <class>Foostor_Weblog_Model</class>
            <!-- 
            need to create our own resource, cant just
            use core_mysql4
            -->
            <resourceModel>weblog_mysql4</resourceModel>
        </weblog> 
        <weblog_mysql4>
            <class>Foostor_Weblog_Model_Mysql4</class>
            <entities>
                <blogpost>
                    <table>blog_posts</table>
                </blogpost>
            </entities>
        </weblog_mysql4>
    </models>
    <resources>
        <weblog_setup>
            <setup>
                <module>Foostor_Weblog</module>
                <class>Foostor_Weblog_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </weblog_setup>
        <weblog_write>
            <connection>
                <use>core_write</use>
            </connection>
        </weblog_write>
        <weblog_read>
            <connection>
                <use>core_read</use>
            </connection>
        </weblog_read>      
    </resources>
    </global>
</config>

这是Setup.php 文件:

另外,在 var/reports 文件夹中的报告中,我发现了此错误消息:

a:5:{i:0;s:102:"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'weblog_setup' for key 'PRIMARY'";i:1;s:1493:"#0 C:\wamp\www\magento\lib\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\wamp\www\magento\lib\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 C:\wamp\www\magento\lib\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `co...', Array)
#3 C:\wamp\www\magento\lib\Varien\Db\Adapter\Pdo\Mysql.php(337): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `co...', Array)
#4 C:\wamp\www\magento\lib\Zend\Db\Adapter\Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `co...', Array)
#5 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Mysql4\Resource.php(96): Zend_Db_Adapter_Abstract->insert('core_resource', Array)
#6 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(290): Mage_Core_Model_Mysql4_Resource->setDbVersion('weblog_setup', '0.1.0')
#7 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(233): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('0', '0.1.0')
#8 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(161): Mage_Core_Model_Resource_Setup->applyUpdates()
#9 C:\wamp\www\magento\app\code\core\Mage\Core\Model\App.php(399): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#10 C:\wamp\www\magento\app\code\core\Mage\Core\Model\App.php(329): Mage_Core_Model_App->_initModules()
#11 C:\wamp\www\magento\app\Mage.php(627): Mage_Core_Model_App->run(Array)
#12 C:\wamp\www\magento\index.php(80): Mage::run('', 'store')
#13 {main}";s:3:"url";s:48:"/magento/index.php/weblog/index/showAllBlogPosts";s:11:"script_name";s:18:"/magento/index.php";s:4:"skin";s:7:"default";}

我在一些帖子中发现,可以通过清除 magento 数据库中 Log_* 表的内容来避免完整性约束违规。但我不确定这是否是我需要做的。请提供建议。谢谢。

Apologize for the lengthy post in advance.

I was following Alan Storm's articles about magento development. I was following the part 6 in that series about Resource setup. I created the resource setup in the config file and placed the Setup.php file appropriately. But if i try to flush the cache or try to access any page of magento, i get a error message : There has been an error processing your request. If i remove the setup part from the config file, everything works perfectly again. Here are my files :
Config.xml file

<config>    
    <modules>
        <Foostor_Weblog>
            <version>0.1.0</version>
        </Foostor_Weblog>
    </modules>
    <frontend>
        <routers>
            <weblog>
                <use>standard</use>
                <args>
                    <module>Foostor_Weblog</module>
                    <frontName>weblog</frontName>
                </args>
            </weblog>
        </routers>
    </frontend> 
    <global>
        <models>
        <weblog>
            <class>Foostor_Weblog_Model</class>
            <!-- 
            need to create our own resource, cant just
            use core_mysql4
            -->
            <resourceModel>weblog_mysql4</resourceModel>
        </weblog> 
        <weblog_mysql4>
            <class>Foostor_Weblog_Model_Mysql4</class>
            <entities>
                <blogpost>
                    <table>blog_posts</table>
                </blogpost>
            </entities>
        </weblog_mysql4>
    </models>
    <resources>
        <weblog_setup>
            <setup>
                <module>Foostor_Weblog</module>
                <class>Foostor_Weblog_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </weblog_setup>
        <weblog_write>
            <connection>
                <use>core_write</use>
            </connection>
        </weblog_write>
        <weblog_read>
            <connection>
                <use>core_read</use>
            </connection>
        </weblog_read>      
    </resources>
    </global>
</config>

This the Setup.php file:

Also in the reports in var/reports folder, i found this error message :

a:5:{i:0;s:102:"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'weblog_setup' for key 'PRIMARY'";i:1;s:1493:"#0 C:\wamp\www\magento\lib\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\wamp\www\magento\lib\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 C:\wamp\www\magento\lib\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `co...', Array)
#3 C:\wamp\www\magento\lib\Varien\Db\Adapter\Pdo\Mysql.php(337): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `co...', Array)
#4 C:\wamp\www\magento\lib\Zend\Db\Adapter\Abstract.php(574): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `co...', Array)
#5 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Mysql4\Resource.php(96): Zend_Db_Adapter_Abstract->insert('core_resource', Array)
#6 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(290): Mage_Core_Model_Mysql4_Resource->setDbVersion('weblog_setup', '0.1.0')
#7 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(233): Mage_Core_Model_Resource_Setup->_upgradeResourceDb('0', '0.1.0')
#8 C:\wamp\www\magento\app\code\core\Mage\Core\Model\Resource\Setup.php(161): Mage_Core_Model_Resource_Setup->applyUpdates()
#9 C:\wamp\www\magento\app\code\core\Mage\Core\Model\App.php(399): Mage_Core_Model_Resource_Setup::applyAllUpdates()
#10 C:\wamp\www\magento\app\code\core\Mage\Core\Model\App.php(329): Mage_Core_Model_App->_initModules()
#11 C:\wamp\www\magento\app\Mage.php(627): Mage_Core_Model_App->run(Array)
#12 C:\wamp\www\magento\index.php(80): Mage::run('', 'store')
#13 {main}";s:3:"url";s:48:"/magento/index.php/weblog/index/showAllBlogPosts";s:11:"script_name";s:18:"/magento/index.php";s:4:"skin";s:7:"default";}

I found in a few posts that Integrity constraint violation can be avoided by clearing the contents of Log_* tables in the magento db. But i am not sure if this is what i need to do. Kindly advice. Thanks.

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

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

发布评论

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

评论(2

瑾夏年华 2024-11-23 15:26:59

您似乎已经在 core_resource 表中拥有 weblog_setup 键,并且由于它是唯一键,因此无法复制。尝试从表中删除该行,并确保您的安装脚本正确运行并且不会产生错误。

You seems to already have weblog_setup key in the core_resource table and since it's an unique key it can't be duplicated. Try to remove that row from the table and also make sure your setup script runs correctly and doesn't produce errors.

哭泣的笑容 2024-11-23 15:26:59

我有类似的问题。原因是我的安装脚本中使用了变量$file。因此它与 Mage_Core_Model_Resource_Setup::_modifyResourceDb 中的变量 $file 发生了冲突。

我不知道情况是否相同,但是,永远不要将安装脚本中的变量命名为 $file$fileName$version< /代码>.

I had similar problem. The reason was that there was used a variable $file in my installation script. So it made a collision with variable $file in Mage_Core_Model_Resource_Setup::_modifyResourceDb.

I don't know whether it is same case, however, never name a variable in installation script as $file, $fileName or $version.

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