gpt4 book ai didi

magento-1.7 - Magento : object->save() does not insert to database

转载 作者:行者123 更新时间:2023-12-04 05:15:56 24 4
gpt4 key购买 nike

model->save()不插入数据库。 Magento 缓存已关闭。
我没有收到任何问题,没关系,但它没有插入到数据库中。
我的代码如下:

try
{
$cusSite = Mage::getModel('themeeditor/customersite');
$cusSite->setData(array("customer_id" => 1,
"website_id" => 1,
"store_group" => 1,
"store_id" => 1));
$query = $cusSite->save();
}
catch(Exception $e)
{
echo $e->getMessage;exit;
}

这是我的 代码\本地\FS\ThemeEditor\etc\config.xml
   <models>
<themeeditor>
<class>FS_ThemeEditor_Model</class>
<resourceModel>themeeditor_mysql4</resourceModel>
</themeeditor>
<themeeditor_mysql4>
<class>FS_ThemeEditor_Model_Mysql4</class>
<entities>
<customersite>
<table>themeeditor_customersite</table>
</customersite>
</entities>
</themeeditor_mysql4>
</models>
<resources>
<themeeditor_setup>
<setup>
<module>FS_ThemeEditor</module>
<class>Mage_catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</themeeditor_setup>
<themeeditor_write>
<connection>
<use>core_write</use>
</connection>
</themeeditor_write>
<themeeditor_read>
<connection>
<use>core_read</use>
</connection>
</themeeditor_read>
</resources>

这是我的 代码\本地\FS\ThemeEditor\Model\Customersite.php
<?php

class FS_ThemeEditor_Model_Customersite extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('themeeditor/customersite');
}
}

这是我的 代码\本地\FS\ThemeEditor\Model\Mysql4\Customersite.php
<?php

class FS_ThemeEditor_Model_Mysql4_Customersite extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
// Note that the billingaddress_id refers to the key field in your database table.
$this->_init('themeeditor/customersite', 'customer_id');
}
}

这是我的 代码\本地\FS\ThemeEditor\Model\Mysql4\Customersite\Collection.php
<?php

class FS_ThemeEditor_Model_Mysql4_Customersite_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('themeeditor/customersite');
}
}

这是我的 code\local\FS\ThemeEditor\sql\themeeditor_setup\mysql4-install-0.1.0.php
<?php 
$installer = $this;

$installer->startSetup();

$installer->run("
DROP TABLE IF EXISTS {$this->getTable('themeeditor_customersite')};
CREATE TABLE {$this->getTable('themeeditor_customersite')}(
`customer_id` int(10) unsigned NOT NULL,
`website_id` int(10) unsigned NOT NULL,
`store_id` int(10) unsigned NOT NULL,
`store_group` int(10) unsigned NOT NULL,
FOREIGN KEY (`customer_id`) REFERENCES {$this->getTable('customer_entity')} (`entity_id`) ,
PRIMARY KEY (`customer_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;");

$installer->endSetup();

我不知道它无法插入数据库的原因。

最佳答案

我有一个类似的问题。因为我的主键不是自动生成的,Magento 看到 Id 字段有一个值并假设保存是更新而不是插入。解决方法是将以下行添加到您的 Model_Resource 类中:

protected $_isPkAutoIncrement = false;

关于magento-1.7 - Magento : object->save() does not insert to database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14264639/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com