MySQL 5.5 報錯"ERROR 1075 (42000): Incorrect table definition"
--給表增加自增欄位的時候報錯
mysql> desc t7;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| id | int(4) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> alter table t7 add id2 int(4) auto_increment;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
報錯原因:自增欄位沒有被定義為一個key。
解決辦法:可以將新增欄位定義為unique key或primary key。
mysql> alter table t7 add id2 int(4) auto_increment primary key;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table t7 drop column id2;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc t7;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| id | int(4) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
解決辦法:可以將新增欄位定義為unique key或primary key。
mysql> alter table t7 add id2 int(4) auto_increment primary key;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table t7 drop column id2;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table t7 add id2 int(4) auto_increment unique key;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2082626/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- MySQL:ERROR 1286 (42000): Unknown storage engine 'MyISAM'MySqlError
- MySQL 8.0.26 bug ERROR 1064(42000) -master-data is deprecated and will be removeMySqlErrorASTREM
- 【BUG記錄】MySQL插入Emoji表情報錯"Incorrect string value"MySql
- MySQL執行語句報Incorrect key file for table '/tmp/#sql_.MYI'; try to repair itMySqlAI
- [報錯:字元太長] SQLSTATE [42000]: Syntax error or access violation: 1071 Specified key was t oo long;字元SQLError
- mysql的ERROR 1231 (42000)問題原因及解決方法MySqlError
- mysqldump匯出報錯"mysqldump: Error 2013 ... during query when dumping tableMySqlError
- mysql 報錯:ERROR 1366 (HY000): Incorrect string value: ‘\xD5\xC5\xC8\xFD‘ for column ‘name‘ at row 1MySqlError
- Qt報Multiple definition錯誤的解決QT
- ERROR 1410 (42000): You are not allowed to create a user with GRANTError
- MySQL 5.6執行DDL報錯ERROR 1050 (42S01): Table 'sms/#sql-ib752' already existMySqlError
- MySQL 啟動報錯 error while loading shared librariesMySqlErrorWhile
- MYSQL報1022錯誤:Can't write;duplicate key in table '.....'MySql
- MySQL案例02:ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGESMySqlError
- MySQL error 錯 誤 碼MySqlError
- MySQL建立觸發器時報錯Error Code: 1064MySql觸發器Error
- ERROR 1045 (28000): ProxySQL Error: 報錯ErrorSQL
- MySQL報錯ERROR 2013 (HY000): Lost connection to MySQL server during queryMySqlErrorServer
- Laravel5.4 資料庫遷移錯誤 SQLSTATE [42000] Syntax error or access violation 1071Laravel資料庫SQLError
- Mysql資料庫報ERROR 1045 (28000)報錯及MySQL忘記密碼找回MySql資料庫Error密碼
- 記一次 打包報錯:Keystore was tampered with, or password was incorrect
- mysql匯入sql檔案報錯 ERROR 2013 2006 2002MySqlError
- MySQL8.0.28命中[ERROR][MY-013183]報錯案例分析MySqlError
- MySQL, Incorrect usage of UNION and ORDER BYMySql
- MySQL 5.6複製報錯Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;MySqlError
- MyIsam 表 “ Incorrect key file for table 't_ '; try to repair it”AI
- 解決ERROR 1231 (42000): Variable 'time_zone' can'tError
- MySQL 報錯 ERROR 1290 (HY000): running with the --secure-file-privMySqlError
- mysql登入報錯提示:ERROR 1045 (28000)的解決方法MySqlError
- beego報錯 table name: `xxx` not existsGo
- SAP對物料做上架報錯 :Definition of totals level is missing for storage type
- MYSQL5.7.22全庫備份匯入MYSQL8.0.20報錯ERROR3554MySqlError
- 【MySQL】ERROR 1290 (HY000): --secure-file-priv--匯出報錯MySqlError
- 修改MySQL資料型別報 Changing columns for table XXX 錯的問題MySql資料型別
- MySQL - DDL詳解(Data Definition Language)MySql
- Larabel遷移檔案時報SQLSTATE[42000]錯誤的解決方法SQL
- 【Redis】slaveof 報錯 Background transfer errorRedisError
- 網站報錯:“Database Server Error”網站DatabaseServerError