MySQL should make the column NOT UNIQUE. Error cannot DROP 'ColumnName'; check if column / key exists

The column name is unique ( UNIQUE KEY ColumnName ).

I just want to make the column not unique (it should be very simple, but not understand how).

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

There is a unique icon in the structure inside the line. But the icon is not clickable.

Like in phpMyAdmin, he did not find how to do this while trying to execute the request.

Based on the tips, tried ALTER TABLE TableName DROP INDEX ColumnName .

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

Here https://stackoverflow.com/questions/548388/ ... found This error means that you are trying to delete a key which is being used by another table. Perhaps the column name is used by another table.

Please advise what needs to be done so that the column is 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 the advice of @Bart Friederichs, I tried ALTER TABLE 18_6_TransactionPartners DROP INDEX Number , and the modified RegistrationNumber column was not unique. I don’t understand why (maybe there was a mess with unique keys). In any case, this may not be unique.

+6
source share
3 answers

Perhaps you have the name INDEX . Using SHOW CREATE TABLE tbl , you can find out the names of the indexes. Then leave them by name (for example, in 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 remove an index, use this:

 ALTER TABLE test DROP INDEX k; 

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

 ALTER TABLE TableName DROP INDEX RegistrationNumber; 
+6
source

If your column has been uniquely defined using the UNIQUE clause, you can do something like this:

 ALTER TABLE mytable DROP INDEX constraint_name 

To remove an index, do the following: -

 ALTER TABLE mytable DROP INDEX index_name; 
+2
source

You need to drop the index using the index name, not the column name.

0
source

Source: https://habr.com/ru/post/951377/


All Articles