Not able to import into mysql `doltdump.sql` due to missing unique key constraint
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 873
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 120
Description
I have a clone of [holywritings/bahaiwritings](https://www.dolthub.com/repositories/holywritings/bahaiwritings) that I ran `dolt dump` on. After removing the `DEFAULT` clause that was causing #10904, I get the following error
```
ERROR 6125 (HY000) at line 293: Failed to add the foreign key constraint. Missing unique key for constraint 'prayer_book_structure_ibfk_1' in the referenced table 'writings'
```
This is statement that creates the `prayer_book_structure_ibfk_1` constraint.
```sql
CREATE TABLE `prayer_book_structure` (
`category_name` varchar(255) NOT NULL,
`phelps_code` varchar(16) NOT NULL,
`source_id` varchar(255),
`version` varchar(255),
`order_in_category` int,
`notes` text,
`source_language` varchar(16) NOT NULL DEFAULT 'en',
`category_order` int DEFAULT '0',
PRIMARY KEY (`source_language`,`category_name`,`phelps_code`),
KEY `phelps_code` (`phelps_code`),
CONSTRAINT `prayer_book_structure_ibfk_1` FOREIGN KEY (`phelps_code`) REFERENCES `writings` (`phelps`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;
```
This is what the `create table` statement for `writings` looks like
```sql
CREATE TABLE `writings` (
`phelps` varchar(16),
`language` varchar(16),
`version` varchar(255) NOT NULL DEFAULT 'uuid()',
`name` varchar(255),
`type` varchar(255),
`notes` text,
`link` varchar(255),
`text` longtext,
`source` varchar(255),
`source_id` varchar(255),
`is_verified` tinyint(1) DEFAULT '1',
PRIMARY KEY (`version`),
KEY `lookup` (`phelps`,`language`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin;
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure by importing the dolt dump for holywritings/bahaiwritings into MySQL, focusing on the prayer_book_structure foreign key and the writings table definition shown here. Trace how dolt dump emits foreign keys and referenced indexes, then verify the fix by importing the dump without the missing unique-key error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100