Hongmu Notes
Home Language Notes Query error: #1075-Incorrect table definition; there can be only one auto column, and it must be defined as a key.
Language Notes mySql

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

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

This error message indicates that you defined multiple auto-increment columns when creating the table, or that you did not define an auto-increment column as a primary key or a unique key; as a result, MySQL was unable to create the table. In MySQL, there can be only one auto-increment column, and it must be defined as a primary key or a unique key. Here are some possible ways to resolve this issue:

  1. Ensure there is only one auto-incrementing column: You should review your table definition to confirm that only one column is defined as an auto-incrementing column. If you need multiple auto-incrementing columns, convert them into regular columns and use another unique key or composite key to ensure data uniqueness.
  2. Define an auto-incrementing column as a primary key or a unique key: When creating a table, you should define an auto-incrementing column as a primary key or a unique key. For example, you can use the following code to create a table with an auto-incrementing column and a primary key:
    CREATE TABLE mytable (
        id INT NOT NULL AUTO_INCREMENT,
        name VARCHAR(50),
        PRIMARY KEY (id)
    );
  3. If you have already created a table and need to define an auto-incrementing column as a primary key or a unique key, please use the following code to make the change:
    ALTER TABLE mytable MODIFY COLUMN id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
在上面的代码中,MODIFY COLUMN用于修改现有列的定义,将其定义为自动递增列和主键。 请注意,如果您已经在表中定义了多个自动递增列,您应该选择其中一个作为主键或唯一键,并删除其他自动递增列。如果您需要使用多个自动递增列,您可以使用其他技术来模拟自动递增行为,例如使用触发器或存储过程。
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

sqlite uses PDO to execute SQL statements exec(), query()

sqlite uses PDO to execute SQL statements exec(), query() Language Notes mySql

In PHP scripts, executing SQL queries using PDO to interact with a database can be done through three different approaches; the choice of which method to use depends on the specific operation you intend to perform. 1. Using the PDO::exec() method: When executing queries such as INSERT, UPDATE, or DELETE that do not return a result set, use the exec() method on a PDO object to execute the query. Upon successful execution, this method returns the number of affected rows...
👁 323
Mysql efficiency improvement: limit this piece of shit

Mysql efficiency improvement: limit this piece of shit Language Notes mySql

In mysql, the efficiency of limit is not high, especially my millions of data, limit 100000, 50, so writing, the query is even slower, at first it was quite fast, and the server cup behind it was directly filled for me! I thought the server was hacked, so I looked for the problem. I looked for it for a few days, but it turned out to be this dog, which made me angry! So I inquired about the principle of limit, emmm, change! Must be changed ...
👁 155
SQL statement to truncate the database

SQL statement to truncate the database Language Notes mySql

The TRUNCATE command can be used to clear a table; however, if you need to clear an entire database, you must clear each table individually. Below is an example SQL statement for clearing an entire database: SET foreign_key_checks = 0; SELECT CONCAT('TRUNCATE TABLE `',table_name,'`;') FR...
👁 297

Recommended reading

(Adaptive Mobile Version) Responsive Blue Mechanical and Electrical Equipment Installation PBootCMS Template – Download HTML5 Mechanical and Electrical Installation Project Website Template (0703)

(Adaptive Mobile Version) Responsive Blue Mechanical and Electrical Equipment Installation PBootCMS Template – Download HTML5 Mechanical and Electrical Installation Project Website Template (0703) Practical Collection pbootcms Template

A responsive blue PbootCMS website template designed for mechanical and electrical installation projects, compatible with both PC and WAP devices. Its professional and sophisticated design is ideal for showcasing mechanical and electrical installation projects, technical expertise, and project case studies. This template helps mechanical and electrical installation companies demonstrate their construction capabilities online and secure project partnerships. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www....
👁 51
Express moving and shipping company website template 0372

Express moving and shipping company website template 0372 Practical Collection Yiyou template

An eyoucms website template for the express delivery, moving and shipping company industries. The design style is efficient and professional, and can showcase express delivery services, moving solutions, shipping business and corporate strength. Helps express moving companies to display their brands online and attract individual and corporate customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation...
👁 51
(PC+WAP) Metal Stainless Steel Screen Manufacturing Company – pbootCMS Template; Download Source Code for Stainless Steel Decoration Project Websites – 0704

(PC+WAP) Metal Stainless Steel Screen Manufacturing Company – pbootCMS Template; Download Source Code for Stainless Steel Decoration Project Websites – 0704 Practical Collection pbootcms Template

A PbootCMS website template designed for companies specializing in stainless steel screens and artisanal products, supporting both PC and WAP devices. Its modern, luxurious design effectively showcases stainless steel decorative projects and intricate craftsmanship details. This template helps stainless steel manufacturers demonstrate their premium customization capabilities online, attracting commercial clients such as hotels and private clubs. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: adm...
👁 32
Responsive sheet metal equipment manufacturing website template 0373

Responsive sheet metal equipment manufacturing website template 0373 Practical Collection Yiyou template

This EyouCMS responsive template is ideal for the sheet metal equipment manufacturing industry, featuring a professional industrial design style that effectively showcases sheet metal equipment products, manufacturing processes, technical specifications, and industrial applications. It enables sheet metal manufacturing enterprises to present their products online and attract industrial customers. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS...
👁 40
Logo image management of Imperial cms website is convenient for subsequent uploading and replacement (use of image information management and PHP call).

Logo image management of Imperial cms website is convenient for subsequent uploading and replacement (use of image information management and PHP call). Program Notes Empire cms

It is inconvenient to use extended variables to manage imperial pictures. Therefore, you can use the empire's own plug-in: picture information management. Usage, as shown above, but more introduction! Here is the calling method! & lt; div class=" logo fl w_img" & gt; & lt; ? php $img=$empire-& gt; fetch1(" SELECT * FROM…
👁 388
(PC+WAP) Mining Drilling Rig – Mining Equipment Website (PBootCMS Template) – Blue Marketing-oriented Mining Machinery and Equipment Website Template Download – 0705

(PC+WAP) Mining Drilling Rig – Mining Equipment Website (PBootCMS Template) – Blue Marketing-oriented Mining Machinery and Equipment Website Template Download – 0705 Practical Collection pbootcms Template

A PbootCMS website template featuring a blue marketing style, specifically designed for the mining drilling rig and mining equipment industry, supporting both PC and WAP devices. The page design focuses on product showcasing and technical specifications, effectively attracting customers in the mining sector. This template helps mining machinery and equipment companies showcase their product capabilities online and generate targeted inquiries. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin...
👁 39