Mysql Error: # 1075

SQL query:

ALTER TABLE `blog` CHANGE `id` `id` BIGINT NOT NULL AUTO_INCREMENT 

MySQL said:

 #1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key 

I am trying to create a blog and I got the code. Now I need to do an automatic id increase, but I get this error. Why am I getting this?

+4
source share
3 answers

MySQL returns this error (most likely) because there is no unique index defined in the id column. (MySQL requires a unique index. Another possibility that you already understand is that there can only be one column defined as AUTO_INCREMENT in a table.)

To make this column AUTO_INCREMENT, you can add a UNIQUE constraint or a PRIMARY KEY constraint in the id column. For instance:

 ALTER TABLE `blog` ADD CONSTRAINT `blog_ux` UNIQUE (`id`) ; 

(Note that this statement returns an error if identical values ​​exist for the id column.)

Alternatively, you can make the id column the main character of the table (if the table does not yet have a PRIMARY KEY constraint).

 ALTER TABLE `blog` ADD PRIMARY KEY (`id`) ; 

(Note that this statement returns an error if there is any duplicate value for the id column, or if there are NULL values ​​in this column, if the table has a PRIMARY KEY constraint.)

+7
source

MySQL requires the auto increment column to be the primary key of the table. Add a primary key constraint to the end

 ALTER TABLE `blog` MODIFY COLUMN `id` BIGINT NOT NULL AUTO_INCREMENT primary key 
+4
source

To resolve message #1075 error , you must mark atleast one column as primary_key or unique_key . what did you forget to do.

Primary _key defining Primary _key in the ID column, my error is resolved by the guys.

thanks,

Anirud Court.

-1
source

All Articles