Magento客户实体表删除表属性中的UNIQUE KEY

时间:2015-11-04 15:29:47

标签: mysql magento magento-1.9.2.1

我需要使用插件的设置脚本更改magento中的默认customer_entity表说明,是否可以删除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`)

2 个答案:

答案 0 :(得分: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();

或者你可以用&#34; magento方式&#34;像这样(未经测试的代码!)

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

答案 1 :(得分:2)

这样做了:

    <?php

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