Magento从1.4.0.1升级到1.9.2.3:升级安装程序引发错误:无法添加外键约束
尝试将magento系统从1.4.0.1升级到最新的1.9.2.3 升级安装程序文件Magento从1.4.0.1升级到1.9.2.3:升级安装程序引发错误:无法添加外键约束,magento,upgrade,magento-1.4,customer,Magento,Upgrade,Magento 1.4,Customer,尝试将magento系统从1.4.0.1升级到最新的1.9.2.3 升级安装程序文件mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php 抛出错误: a:5:{i:0;s:199:"Error in file: "app/code/core/Mage/Customer/sql/ customer_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php" - SQLSTATE[HY000]: General error: 1215 Cann
mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php
抛出错误:
a:5:{i:0;s:199:"Error in file: "app/code/core/Mage/Customer/sql/
customer_setup/mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php" - SQLSTATE[HY000]:
General error: 1215 Cannot add foreign key constraint";i:1;s:970:"
#0 app/code/core/Mage/Core/Model/Resource/Setup.php(644): Mage::exception('Mage_Core', 'Error in file: ...')
- 如何解决此问题
- 错误的原因是什么李>
attribute\u id
$installer->run("
CREATE TABLE `{$installer->getTable('customer/form_attribute')}` (
`form_code` char(32) NOT NULL,
`attribute_id` smallint UNSIGNED NOT NULL,
PRIMARY KEY(`form_code`, `attribute_id`),
KEY `IDX_CUSTOMER_FORM_ATTRIBUTE_ATTRIBUTE` (`attribute_id`),
CONSTRAINT `FK_CUSTOMER_FORM_ATTRIBUTE_ATTRIBUTE` FOREIGN KEY (`attribute_id`) REFERENCES `{$installer->getTable('eav_attribute')}` (`attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Customer attributes/forms relations';
");
但是您也可以看到,字段属性\u id
被创建为最小但没有长度
由于此链接指向表eav_属性
,您现在可以尝试从要创建的虚拟表中比较字段类型和smallint
类型的字段
CREATE TABLE `dummy_table` (`attribute_id` smallint UNSIGNED NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8;
# you should now have the table named "dummy_table"
show fields from dummy_table where field = 'attribute_id';
# the Type should be "smallint(5) unsigned" and Null should be "No", if not, that is why the foreign key creation fail.
show fields from eav_attribute where field = 'attribute_id';
# the Type should be "smallint(5) unsigned" and Null should be "No"
drop table `dummy_table`;
# clean up of our testing table
决议:
因此,现在,如果字段eav\u attribute.attribute\u id
不是smallint(5)unsigned not null
,那么您可以安全地编辑eav\u attribute.attribute\u id
,使其smallint(5)unsigned not null
如果您在虚拟表中创建的字段不是smallint(5)unsigned not null
,那么只需编辑文件mysql4-upgrade-1.4.0.0.7-1.4.0.0.8.php的第34行即可正确创建该字段
// `attribute_id` smallint UNSIGNED NOT NULL, -- old line
`attribute_id` smallint(5) UNSIGNED NOT NULL, // new line, so the field have the right type
这可能是数据库引擎的问题。几个月前我也遇到过类似的问题,所以我将更新后的magento数据库表引擎与1.9数据库表引擎进行了比较,发现所有表都将MyISAM作为数据库引擎,所以我将其更改为1.9数据库,我的问题得到了解决 这是什么?这与安装/升级文件有关,我在谷歌搜索时看到了这个结果,但我不确定这是否能帮到你。你能试着找出该文件中到底有什么不起作用吗?如果你做了一个die('ok')代码>在创建customer/form_属性表之前,它是否有效?如果在创建表之后立即执行此操作,它是否仍然有效?还是你得到了错误?谢谢你的回答。我将检查更改为attribute\u id smallint(5)UNSIGNED NOT NULL
,但仍然得到相同的错误显示来自eav\u属性的字段,其中字段='attribute\u id'
显示了什么?表customer\u form\u attribute
是否已经存在于数据库中?如果创建了表,那么,在CREATETABLE语句之后,应该还有其他东西会失败,对吗?你能指出是哪条线在做这件事吗?添加一个简单的die('ok')
,并将其从php行移动到php行,实际上会告诉我们是什么指令导致该操作失败
// `attribute_id` smallint UNSIGNED NOT NULL, -- old line
`attribute_id` smallint(5) UNSIGNED NOT NULL, // new line, so the field have the right type