开发者

Problem with resource setup in magento

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 perfect开发者_如何学运维ly 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜