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

Magento customer entity table remove UNIQUE KEY in table properties

我需要用我的插件设置脚本更改 magento 中的默认 customer_entity table 描述,是否可以让它删除 UNIQUE KEY 字段?

magento customer_entity table 结构描述为:

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`)

您可以 运行 sql 在 update/install 脚本中查询:

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

或者您可以像这样在 "magento way" 中执行此操作(未经测试的代码!)

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

是这样做的:

    <?php

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