What is wrong with my SQL here? #1089 - Incorrect prefix key

后端 未结 13 1790
迷失自我
迷失自我 2020-12-01 02:21
CREATE TABLE `table`.`users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(         


        
相关标签:
13条回答
  • 2020-12-01 03:14

    In PHPMyAdmin, Ignore / leave the size value empty on the pop-up window.

    0 讨论(0)
  • 2020-12-01 03:15

    In your PRIMARY KEY definition you've used (id(11)), which defines a prefix key - i.e. the first 11 characters only should be used to create an index. Prefix keys are only valid for CHAR, VARCHAR, BINARY and VARBINARY types and your id field is an int, hence the error.

    Use PRIMARY KEY (id) instead and you should be fine.

    MySQL reference here and read from paragraph 4.

    0 讨论(0)
  • 2020-12-01 03:15

    Here the full solution step by step

    • First of all you have to make the table by inserting all the data. id should AI ticked.
    • then press go and #1089 error will be pop-up

    here is the solution

    • theres a button near go called preview SQL
    • click that button and copy the sql code
    • then click on SQL tab on top of the window
    • Clear the text filed and paste that copied code there.
    • you will be see (id (11)) this on bottom of the code
    • replace (id (11)) into (id)
    • and click go

    boom now you will be fine

    0 讨论(0)
  • 2020-12-01 03:19

    This

    PRIMARY KEY (id (11))

    is generated automatically by phpmyadmin, change to

    PRIMARY KEY (id)

    .

    0 讨论(0)
  • 2020-12-01 03:20

    When you give id as a primary key then a pop up is come and those aske you to how many size of this primary key. So you just leave blank because by default int value is set 11. Click then ok on those pop up without any enter a number. in this type of error never will you face in future. Thank you

    0 讨论(0)
  • 2020-12-01 03:22

    If you are using a GUI and you are still getting the same problem. Just leave the size value empty, the primary key defaults the value to 11, you should be fine with this. Worked with Bitnami phpmyadmin.

    0 讨论(0)
提交回复
热议问题