惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
腾讯CDC
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
阮一峰的网络日志
阮一峰的网络日志
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
博客园 - Franky
Y
Y Combinator Blog
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
Martin Fowler
Martin Fowler
雷峰网
雷峰网
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More

MySQL Forums

MySQL :: Workbench update to 26.7.0 MySQL :: Upgrade Problems Starting a Discussion About Database Migration Best practices for indexing large tables with frequent updates? Discrepancy in Compatibility statement with MySQL and Connector/J 26.7 Announcing August 2026 Releases featuring MySQL Server, MySQL NDB Cluster, Shell and Connector/ODBC How to Troubleshoot Slow MySQL Queries Using EXPLAIN and Indexes The future of the timestamp data type Linking 2 cells in a table MySQL :: MySQL syntax error replication from 8.0 to 8.4 error How should I design a MySQL schema for storing construction material calculations? (no replies) Can AI analyze market trends faster than traditional trading (no replies) This CMD window bothers me. Announcing July 2026 Releases featuring MySQL Server 26.7.0, 9.7.2 and 8.4.11 Can I purge binlog files after migration ? Can't update expired password in Mysql Workbench Assistance with MySql application and Sql server MySQL :: MySQL Community Governance Model Announcing June 2026 Releases featuring MySQL Server 9.7.1 and 8.4.10 GoHighLevel Webhook Data in MySQL I'm troubleshooting MySQL query performance (no replies) What could cause .frm and .ibd mismatches across multiple tables? Problem with creating a connection to a remote database on local network Best MySQL schema for storing image processing jobs? APT Repository not working on Ubuntu 26.04 How do you create a remote connection to a database (no replies) MySQL :: storing and reading blob ODBC Connector almost always alters it's name and path MySQL :: Connector/Windows
Two tables with bidirectional relationships
Magnus Mülle · 2026-04-21 · via MySQL Forums

Two tables with bidirectional relationships

Posted by: Magnus Müller
Date: April 18, 2026 10:42AM


Hello,

i am new two MySQL and i am trying to setup my first project which is based on an existing DB (non MySQL).

Now i face a problem.

I have two tables: Departments and Persons. Both tables have unique primary keys.

Each department has a person as head of the department. 1:N This relationship formed no problem.

The second relationship says that every person can belong to a department. But this is not mandatory. So this relationship is 1:N but in the opposite direction.

When i try to send my model to the DB i get a nice little error message (as many i suppose):

Executing SQL script in server
ERROR: Error 6125: Failed to add the foreign key constraint. Missing unique key for constraint 'fk_tbl_persons_tbl_departments1' in the referenced table 'tbl_departments'
SQL Code:
ALTER TABLE `mydb`.`tbl_persons`
ADD CONSTRAINT `fk_tbl_persons_tbl_addresses1`
FOREIGN KEY (`per_adr_index`)
REFERENCES `mydb`.`tbl_addresses` (`adr_index`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_tbl_persons_tbl_departments1`
FOREIGN KEY (`per_dep_index`)
REFERENCES `mydb`.`tbl_departments` (`dep_index`)
ON DELETE NO ACTION
ON UPDATE NO ACTION

I am not sure if i am doing something here which is not possible or what the error might be or how i have to deal with this situation.


Subject

Written By

Posted

Two tables with bidirectional relationships

April 18, 2026 10:42AM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.