Mysql 1089 ошибка

CREATE TABLE `table`.`users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`(11))
) ENGINE = MyISAM;

I’m getting the #1089 - Incorrect prefix key error and can’t figure out what I’m doing wrong.

Dharman's user avatar

Dharman

30.4k22 gold badges84 silver badges132 bronze badges

asked Mar 8, 2015 at 21:47

sandorfalot's user avatar

2

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.

answered Mar 8, 2015 at 21:58

0

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.

answered Sep 18, 2015 at 23:20

Raphael Amponsah's user avatar

1

This

PRIMARY KEY (id (11))

is generated automatically by phpmyadmin, change to

PRIMARY KEY (id)

.

answered Apr 17, 2016 at 2:19

Rafael Helizio Serrate Zago's user avatar

0

There is a simple way of doing it. This may not be the expert answer and it may not work for everyone but it did for me.

Uncheck all primary and unique check boxes, jut create a plain simple table.

When phpmyadmin (or other) shows you the table structure, make the column primary by the given button.

Then click on change and edit the settings of that or other colums like ‘unique’ etc.

answered Aug 5, 2015 at 12:40

Robot Boy's user avatar

Robot BoyRobot Boy

1,8361 gold badge17 silver badges17 bronze badges

CREATE TABLE `table`.`users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`(11))
) ENGINE = MyISAM;

Change To

CREATE TABLE `table`.`users` (
        `id` INT(11) NOT NULL AUTO_INCREMENT,
        `username` VARCHAR(50) NOT NULL,
        `password` VARCHAR(50) NOT NULL,
        `dir` VARCHAR(100) NOT NULL,
        PRIMARY KEY (`id`)
    ) ENGINE = MyISAM;

answered Mar 3, 2017 at 16:16

Roshan Padole's user avatar

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

answered Oct 22, 2019 at 16:06

Malith Ileperuma's user avatar

In my case, i faced the problem while creating table from phpmyadmin. For id column i choose the primary option from index dropdown and filled the size 10.

If you’re using phpmyadmin, to solve this problem change the index dropdown option again, after reselecting the primary option again it’ll ask you the size, leave it blank and you’re done.

answered Oct 23, 2018 at 17:05

sh6210's user avatar

sh6210sh6210

4,0761 gold badge36 silver badges27 bronze badges

It works for me:

CREATE TABLE `users`(
    `user_id` INT(10) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(255) NOT NULL,
    `password` VARCHAR(255) NOT NULL,
    PRIMARY KEY (`user_id`)
) ENGINE = MyISAM;       

Community's user avatar

answered Sep 16, 2015 at 13:29

Issac Nguyen's user avatar

1

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 😊

answered Jun 30, 2017 at 3:37

hemant rao's user avatar

hemant raohemant rao

2,0572 gold badges12 silver badges13 bronze badges

Problem is the same for me in phpMyAdmin. I just created a table without any const.
Later I modified the ID to a Primary key. Then I changed the ID to Auto-inc.
That solved the issue.

ALTER TABLE `users` CHANGE `ID` `ID` INT(11) NOT NULL AUTO_INCREMENT;

Francisco's user avatar

Francisco

10.8k6 gold badges34 silver badges45 bronze badges

answered Apr 7, 2017 at 7:28

Arindam's user avatar

ArindamArindam

6678 silver badges15 bronze badges

I also had this same problem.
Solution work for me:

CREATE TABLE IF NOT EXISTS `users` (
  `sr_no` int(11) NOT NULL AUTO_INCREMENT,
  `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(100) NOT NULL,
  PRIMARY KEY (`sr_no`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

I paste this code in SQL and run, it works fine.

answered Aug 23, 2016 at 12:06

sayali's user avatar

1

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

answered Oct 27, 2020 at 16:34

Engr. Kazi Shahadat Hossain's user avatar

according to the latest version of MySQL (phpMyAdmin), add a correct INDEX while choosing primary key. for example: id[int] INDEX 0 ,if id is your primary key and at the first index.
Or,


For your problem try this one

CREATE TABLE `table`.`users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE = MyISAM;

Adowrath's user avatar

Adowrath

70211 silver badges24 bronze badges

answered Sep 17, 2015 at 10:32

Omar Faruk's user avatar

Omar FarukOmar Faruk

3912 silver badges8 bronze badges

1

This worked for me:

CREATE TABLE `table`.`users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(50) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `dir` VARCHAR(100) NOT NULL,
    PRIMARY KEY (`id`(id))
) ENGINE = MyISAM;

No need to put id(11) because, by default, it is equal to 11 so you leave
it as id and in phpmyadmin you leave it empty.

Nick's user avatar

Nick

4,67918 gold badges31 silver badges47 bronze badges

answered May 5, 2021 at 16:51

twizelissa's user avatar

Drop the table.user and just use user
The lenght of the id was alread specified in the
id INT(11) and does not need to be specified in the PRIMART KEY.

CREATE TABLE users
(
id INT(11) NOT NULL AUTO_INCREMENT,
username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
dir VARCHAR(100) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE = MyISAM;

answered Nov 6, 2022 at 7:11

Nexpulse's user avatar

CREATE TABLE `movies`.`movie`
( `movie_id` INT(3) NULL AUTO_INCREMENT, `movie_name` VARCHAR(25) NULL,
  `movie_embedded_id` VARCHAR(50) NULL, `rating_no` INT(3) NULL,
  `movie_description` VARCHAR(50) NULL, PRIMARY KEY (`movie_id`(3))) ENGINE = InnoDB;

I keep getting this error:

#1089 — Incorrect prefix key; the used key part isn’t a string, the used length is longer than the key part, or the storage engine doesn’t
support unique prefix keys.

but I’ve got no idea what it means, anyone have a clue?

BS-0

4 / 4 / 3

Регистрация: 13.11.2012

Сообщений: 74

1

13.05.2015, 11:12. Показов 24124. Ответов 2

Метки нет (Все метки)


Студворк — интернет-сервис помощи студентам

При создании таблицы в БД вылазит ошибка #1089 — Incorrect prefix key; the used key part isn’t a string, the used length is longer than the key part, or the storage engine doesn’t support unique prefix keys.

SQL
1
2
3
4
5
6
7
8
9
10
11
12
13
CREATE TABLE `busoop8x_oc`.`oc_zavki` 
( 
`z_zavki` INT(3) NOT NULL AUTO_INCREMENT , 
`z_paket` VARCHAR(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_fam` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_name` VARCHAR(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_otch` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_ulica` VARCHAR(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_dom` VARCHAR(7) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_kv` VARCHAR(7) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
`z_tel` VARCHAR(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL , 
PRIMARY KEY (`z_zavki`(1))
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;

Что это может быть?



0



Programming

Эксперт

94731 / 64177 / 26122

Регистрация: 12.04.2006

Сообщений: 116,782

13.05.2015, 11:12

2

0 / 0 / 0

Регистрация: 06.02.2016

Сообщений: 1

11.06.2017, 09:15

3

Спасибо тебе, добрый человек!!



0



CREATE TABLE `movies`.`movie`
( `movie_id` INT(3) NULL AUTO_INCREMENT, `movie_name` VARCHAR(25) NULL,
  `movie_embedded_id` VARCHAR(50) NULL, `rating_no` INT(3) NULL,
  `movie_description` VARCHAR(50) NULL, PRIMARY KEY (`movie_id`(3))) ENGINE = InnoDB;

Я продолжаю получать эту ошибку:

# 1089 — Неправильный префиксный ключ; используемая ключевая часть не является строкой, используемая длина длиннее ключевой части, или механизм хранения не поддержка уникальных префиксных ключей.

но я понятия не имею, что это значит, у кого есть ключ?

4b9b3361

Ответ 1

С частью

PRIMARY KEY (`movie_id`(3))

вы сообщаете mysql для создания ключа вспомогательной части * для первых трех букв идентификатора фильма. Это работает только для типов строк.

Вам нужно использовать

PRIMARY KEY (`movie_id`)

без предоставления длины.

* Является ли это уверенным, что запрос приводит к ошибке? Никогда не видел этого на первичном ключе, его использовали для индексов.

Мы хотим создать таблицу в базе данных mysql, но она не работает должным образом.

Отображается сообщение об ошибке:

# 1089 -Неверный префиксный ключ; используемая часть ключа не является строкой, используемая длина больше, чем часть ключа, или механизм хранения не поддерживает уникальные префиксные ключи.

Это код:

CREATE TABLE `student_billing`.`payment` (
`id` INT(10) NOT NULL AUTO_INCREMENT ,
`student_name` INT(255) NOT NULL ,
`student_roll` INT(255) NOT NULL ,
`student_batch_id` INT(255) NOT NULL ,
`student_course_name` INT(255) NOT NULL ,
`student_paid_ammount` INT(255) NOT NULL ,
`student_paid_date` DATETIME(6) NOT NULL , 
`student_payment_recivedby` INT(255) NULL ,
 PRIMARY KEY (`id`(10))) ENGINE = MyISAM COMMENT = 'Students Billing DB';

2 ответа

Лучший ответ

/ Информация о DDL /

CREATE TABLE `payment` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `student_name` INT(255) NOT NULL,
  `student_roll` INT(255) NOT NULL,
  `student_batch_id` INT(255) NOT NULL,
  `student_course_name` INT(255) NOT NULL,
  `student_paid_ammount` INT(255) NOT NULL,
  `student_paid_date` DATETIME NOT NULL,
  `student_payment_recivedby` INT(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MYISAM DEFAULT CHARSET=latin1 COMMENT='Students Billing DB'


0

matinict
14 Фев 2016 в 12:11

Вам не нужно указывать длину поля при объявлении ПЕРВИЧНОГО КЛЮЧА. Попробуйте вместо этого:

CREATE TABLE `student_billing`.`payment` (
  `id` INT(10) NOT NULL AUTO_INCREMENT,
  `student_name` INT(255) NOT NULL,
  `student_roll` INT(255) NOT NULL,
  `student_batch_id` INT(255) NOT NULL,
  `student_course_name` INT(255) NOT NULL,
  `student_paid_ammount` INT(255) NOT NULL,
  `student_paid_date` DATETIME(6) NOT NULL,
  `student_payment_recivedby` INT(255) NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM COMMENT='Students Billing DB';


2

hasumedic
14 Фев 2016 в 12:02

Понравилась статья? Поделить с друзьями:
  • Myhost ошибка 1
  • Myhomelib ошибка 10061
  • Myheritage произошла ошибка пожалуйста попытайтесь еще раз позже
  • Mydss ошибка 248
  • Mydss ошибка 209 пользователь удален как восстановить