【问题标题】:Magento customer entity table remove UNIQUE KEY in table propertiesMagento 客户实体表删除表属性中的 UNIQUE KEY
【发布时间】:2015-11-04 15:29:47
【问题描述】:

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

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

【问题讨论】:

  • 究竟是什么问题?您不能从脚本中删除该行吗?
  • 根据 magento 参考,应该使用安装脚本而不是 sql,我上面提供的代码只是描述表的转储

标签: mysql magento magento-1.9


【解决方案1】:

您可以在更新/安装脚本中运行 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 方式”执行此操作(未经测试的代码!)

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

【讨论】:

    【解决方案2】:

    这样做的:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      • 2012-11-04
      • 1970-01-01
      相关资源
      最近更新 更多