2015-11-04 46 views
0

我需要用我的插件的安装脚本更改magento中的默认customer_entity表描述,是否可以使其删除UNIQUE KEY字段?Magento客户实体表删除表属性中的UNIQUE KEY

Magento的customer_entity表结构描述为:

CREATE TABLE `customer_entity` (
    `entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Id', 
    `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id', 
    `attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute Set Id', 
    `website_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Website Id', 
    `email` varchar(255) DEFAULT NULL COMMENT 'Email', 
    ... 
    UNIQUE KEY `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID` (`email`,`website_id`), 
    ... 

所以我需要的是让它删除这一项与安装脚本

UNIQUE KEY `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID` (`email`,`website_id`) 
+0

究竟似乎是问题吗?你不能从脚本中删除该行吗? – Mureinik

+0

根据magento参考它应该与安装脚本不使用SQL,我上面提供的代码只是一个转储,描述一个表 –

回答

3

你可以在更新运行SQL查询/安装脚本:

<?php 
$installer = $this; 
$installer->startSetup(); 
$sql= 'ALTER TABLE `customer_entity` DROP INDEX `UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID`' 
$installer->run($sql); 
$installer->endSetup(); 

或者你可以在“magento方式”中执行l IKE在此(!未经测试的代码)

<?php 
$installer = $this; 
$installer->getConnection()->dropKey('customer_entity', 'UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID') 
$installer->endSetup(); 
1

做这样的说法:

<?php 

    $installer = $this; 
    $connection = $this->getConnection(); 
    $table = $installer->getTable('customer/entity'); 
    $connection->dropIndex($table, 'UNQ_CUSTOMER_ENTITY_EMAIL_WEBSITE_ID'); 
    $installer->endSetup();