mysql删除列出现错误,MySQL需要使列不是唯一的。错误无法删除'ColumnName';检查列/键是否存在...

ColumnName is Unique (UNIQUE KEY ColumnName).

I just want to make column not unique (must be very simple, but can not understand how).

If in phpMyAdmin check at column name and at bottom click on Unique icon, get #1062 - Duplicate entry '' for key 'RegistrationNumber'. OK, see it is because, clicking on icon it ADD UNIQUE.

There is Unique icon in Structure within row. But the icon is not click-able.

As in phpMyAdmin did not found how to do it, trying with query.

Based on advices tried ALTER TABLE TableName DROP INDEX ColumnName.

Get 1091 Can't DROP 'ColumnName'; check that column/key exists

Here https://stackoverflow.com/a/4414694/2465936 found This error means that you are trying to delete a key which is being used by another table. Possibly the ColumnName is used by another table.

Please advice what need to do to make column not unique.

With SHOW CREATE TABLE get

Array

(

[0] => Array

(

[Table] => 18_6_TransactionPartners

[Create Table] => CREATE TABLE `18_6_TransactionPartners` (

`Number` int(11) NOT NULL AUTO_INCREMENT,

`CompanyName` char(255) COLLATE utf8_unicode_ci NOT NULL,

`RegistrationNumber` char(255) COLLATE utf8_unicode_ci NOT NULL,

.......

PRIMARY KEY (`Number`),

UNIQUE KEY `Number_2` (`Number`),

UNIQUE KEY `CompanyName` (`CompanyName`,`RegistrationNumber`),

KEY `Number` (`Number`)

) ENGINE=InnoDB AUTO_INCREMENT=444 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

)

)

Update

Based on @Bart Friederichs advice tried ALTER TABLE 18_6_TransactionPartners DROP INDEX Number and changed column RegistrationNumber not not unique. Do not understand why (possibly had some mess with unique keys). In any case can change to not unique.

解决方案

Probably you have a named INDEX. By using SHOW CREATE TABLE tbl you can find out the names of the indices. Then drop them by name (e.g. some test table):

mysql> SHOW CREATE TABLE test;

CREATE TABLE `test` (

`entry_id` int(11) DEFAULT NULL,

`user_id` int(11) DEFAULT NULL,

UNIQUE KEY `k` (`entry_id`)

)

To drop the index, use this:

ALTER TABLE test DROP INDEX k;

Your key name is RegistrationNumber (as is told by the error message):

ALTER TABLE TableName DROP INDEX RegistrationNumber;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值