Ошибка 1826 mysql

I have imported in MySQL Workbench some tables as .csv files which were exported from Microsoft Access, and then i have set some relations. When I try to Synchronize Model I get this strange error:...

Normally I’d assume this is the fault of Microsoft Access, since Access frequently fails to conform to standard SQL. But this time it’s the fault of MySQL.

This is a bug in MySQL: https://bugs.mysql.com/bug.php?id=72751

Constraint names are supposed to be case-sensitive, per https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html:

Object names may be considered duplicates if their uppercase forms are equal according to a binary collation.

In other words, some object names are case-insensitive.

That is true for names of cursors, conditions, procedures, functions, savepoints, stored routine parameters, stored program local variables, and plugins. It is not true for names of columns, constraints, databases, partitions, statements prepared with PREPARE, tables, triggers, users, and user-defined variables.

That says that constraint names are one of the object types whose names are supposed to case-sensitive.

But that documentation is incorrect. Currently MySQL treats constraint names as case-insensitive. So constraints named idMarca and IdMarca conflict.

We can demo this:

mysql> create table parent (id int primary key);
Query OK, 0 rows affected (0.01 sec)

mysql> create table child1 (parent int, constraint con foreign key (parent) references parent(id));
Query OK, 0 rows affected (0.01 sec)

mysql> create table child2 (parent int, constraint Con foreign key (parent) references parent(id));
ERROR 1826 (HY000): Duplicate foreign key constraint name 'Con'

That’s the error message in MySQL 8.0. The names con and Con should be treated as distinct, but they aren’t.

In older versions of MySQL, the error message wasn’t clear, something like «1050: Table ‘./test/child2’ already exists».

How to fix this? You’ll have to create your foreign key constraints manually.

This bug was reported in 2014, and hasn’t been fixed, so I wouldn’t get your hopes up that it will be fixed soon. You may click the «Affects Me» button in the bug tracker to vote for it to get some attention, but don’t count on it. Just fix the constraint names in your project.

GNOM003

0 / 0 / 0

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

Сообщений: 11

1

30.05.2020, 15:01. Показов 13004. Ответов 3

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


Импортировал модель БД в скрипт и тут такая ошибка:

Executing SQL script in server
ERROR: Error 1826: Duplicate foreign key constraint name ‘aircraft_id’
SQL Code:

MySQL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
        -- -----------------------------------------------------
        -- Table `RedWingsDatabase`.`Control`
        -- -----------------------------------------------------
        CREATE TABLE IF NOT EXISTS `RedWingsDatabase`.`Control` (
          `id` INT NOT NULL,
          `commander_id` INT NULL,
          `aircraft_id` INT NULL,
          `start_date` DATE NULL,
          `end_date` DATE NULL,
          PRIMARY KEY (`id`),
          INDEX `commander_id_idx` (`commander_id` ASC) VISIBLE,
          INDEX `aircraft_id_idx` (`aircraft_id` ASC) VISIBLE,
          CONSTRAINT `commander_id`
            FOREIGN KEY (`commander_id`)
            REFERENCES `RedWingsDatabase`.`Aircraft commander` (`id`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION,
          CONSTRAINT `aircraft_id`
            FOREIGN KEY (`aircraft_id`)
            REFERENCES `RedWingsDatabase`.`Aircraft` (`id`)
            ON DELETE NO ACTION
            ON UPDATE NO ACTION)
        ENGINE = InnoDB

SQL script execution finished: statements: 10 succeeded, 1 failed

Fetching back view definitions in final form.
Nothing to fetch

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



407 / 361 / 141

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

Сообщений: 1,028

30.05.2020, 16:23

2

какая у вас версия mysql?



0



0 / 0 / 0

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

Сообщений: 11

30.05.2020, 16:41

 [ТС]

3

Цитата
Сообщение от retvizan
Посмотреть сообщение

какая у вас версия mysql?

8.0



0



retvizan

407 / 361 / 141

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

Сообщений: 1,028

30.05.2020, 18:13

4

Лучший ответ Сообщение было отмечено GNOM003 как решение

Решение

уберите явное именование ограничения
вместо:

MySQL
1
2
3
4
5
CONSTRAINT `aircraft_id`
FOREIGN KEY (`aircraft_id`)
REFERENCES `RedWingsDatabase`.`Aircraft` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)

нужно:

MySQL
1
2
3
4
FOREIGN KEY (`aircraft_id`)
REFERENCES `RedWingsDatabase`.`Aircraft` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)

или вместо `aircraft_id` используйте уникальное имя в пределах базы



1



Я пишу код на MySQL, и это дает мне ошибки.

Это мой код, и он выдает ошибку — «Код ошибки: 1826. Повторяющееся имя ограничения внешнего ключа ‘menu_ibfk_1’»

Когда я даю другое имя ограничения, появляется ошибка — «Код ошибки: 1822. Не удалось добавить ограничение внешнего ключа. Отсутствует индекс для ограничения ‘menu_ibfk_2’ в указанной таблице ‘menu’»

create database WasteManagement;
CREATE TABLE WasteManagement.Faculty_login ( 
Faculty_ID int(9) NOT NULL  ,
FName varchar(50) DEFAULT NULL,
Department varchar(20) DEFAULT NULL, 
Password varchar(20) DEFAULT NULL, 
PRIMARY KEY (Faculty_ID) );

CREATE TABLE WasteManagement.Student_login ( 
Enrollment_No int(11) NOT NULL , 
SName varchar(50) DEFAULT NULL, 
Course varchar(20) DEFAULT NULL, 
Password varchar(20) DEFAULT NULL, 
PRIMARY KEY (Enrollment_No) );

CREATE TABLE WasteManagement.Staff_login ( 
Staff_ID int(9) NOT NULL  ,
CName varchar(50) DEFAULT NULL,
Username varchar(20) DEFAULT NULL, 
Password varchar(20) DEFAULT NULL, 
PRIMARY KEY (Staff_ID) );

CREATE TABLE WasteManagement.Menu ( 
Staff_ID int(9) NOT NULL,
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
PRIMARY KEY (Datee, Timee, Dish)
#FOREIGN KEY (Staff_ID) References Menu(Staff_ID) 
);

CREATE TABLE WasteManagement.Demand1 ( 
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
S_demand BOOLEAN DEFAULT FALSE, 
PRIMARY KEY (Datee, Timee, Dish, S_demand),
KEY d1 (datee),
KEY t1 (Timee),
KEY dish1 (Dish),
#KEY `AuthorID` (`AuthorID`),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Datee) References Menu(Datee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Timee) References Menu(Timee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Dish) References Menu(Dish));

CREATE TABLE WasteManagement.Demand2 ( 
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
F_demand BOOLEAN NOT NULL DEFAULT FALSE, 
PRIMARY KEY (Datee, Timee, Dish, F_demand),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Datee) References Menu(Datee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Timee) References Menu(Timee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Dish) References Menu(Dish));

CREATE TABLE WasteManagement.Feedback1 ( 
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
eaten_by1 int(7) NOT NULL, 
s_rating int(1) NOT NULL,
PRIMARY KEY (Datee, Timee, Dish, eaten_by1, s_rating),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Datee) References Menu(Datee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Timee) References Menu(Timee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Dish) References Menu(Dish));

CREATE TABLE WasteManagement.Feedback2 ( 
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
eaten_by2 int(7) NOT NULL, 
f_rating int(1) NOT NULL,
PRIMARY KEY (Datee, Timee, Dish, eaten_by2, f_rating),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Datee) References Menu(Datee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Timee) References Menu(Timee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Dish) References Menu (Dish));

CREATE TABLE WasteManagement.Wastage ( 
Datee date NOT NULL DEFAULT 0,
Timee varchar(10) NOT NULL,
Dish varchar(30) NOT NULL, 
Produced_qty int(7) NOT NULL, 
Wasted_qty int(7) NOT NULL,
PRIMARY KEY (Datee, Time, Dish, Produced_qty, Wasted_qty),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Datee) References Menu(Datee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Timee) References Menu(Timee),
CONSTRAINT `menu_ibfk_1` FOREIGN KEY (Dish) References Menu(Dish));

Это снимок вывода MySQL

Снимок вывода MySQL

Что я делаю не так?

Понравилась статья? Поделить с друзьями:
  • Ошибка 1907 не удалось зарегистрировать шрифт office 2013
  • Ошибка 18253 туарег
  • Ошибка 1907 не удалось зарегистрировать шрифт office 2010 windows 10
  • Ошибка 18228 пассат б5
  • Ошибка 1907 майкрософт офис