Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

MySQL foreign keys not automatically detected and related in powerbi

Hi, 

 

I've been stuck with this problem for the past few days where the foreign key exists as showed in the SQL table schema. However, when the tables are imported to powerbi, some relationships are not automatically formed. I initially thought that it was due to Many-to-Many relationships only, so I transformed these to 1 to many or 1 to 1. This did not solve the issue of powerbi not being able to interpret the relationships formed in SQL. 

 

I've gone through so many iterations with chatgpt, but none of the solutions works. As it stands, the foreign key relationships form correctly within MySQL.

GOAL in auto relationship: I want these to automatically form based on the relationship structure defined in the SQL schema because I want users that import this data to have as little work to do as possible in figuring out the relationships by themselves. The default schema should help users to only import this data and analyse it directly instead of having to sort the relationships out. 

 

Issue: audits to audittemplates 

 

ALTER TABLE audits
ADD CONSTRAINT fk_audits_template_to_audittemplates
FOREIGN KEY (template) REFERENCES audittemplates(couchdbid)
ON DELETE SET NULL;

 

william_analyst_0-1727096121648.png

 

william_analyst_1-1727096165503.png

 

Really appreciate if I can get some advice on how to solve this. 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Solved: Used primary to connect and now it works

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Solved: Used primary to connect and now it works

parry2k
Super User
Super User

@Anonymous I wouldn't rely on auto relationship, full stop. I rather spend time making users understand the relationships and how it work. If someone is working on Power BI models and don't want to spend time on looking at the relationship then something is wrong. This is the key to any successful Power BI project and rather spend time on looking these things are first place than relying on the auto relationship. Good luck!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Anonymous As a best practice you should manually set the relationship instead of auto-relationship. The wrong relationship can lead to unexpected results so it is better to do it manually and make sure the correct columns are used in the relationship and the relationship type is correct.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi @parry2k  , 

Thanks for the quick comment! 

So I want these to automatically form based on the relationship structure defined in the SQL schema because I want users that import this data to have as little work to do as possible in figuring out the relationships by themselves. The default schema should help users to only import this data and analyse it directly instead of having to sort the relationships out. 

uzuntasgokberk
Super User
Super User

Hello @Anonymous,

Relationshipt not automatically formed is better. Sometimes it creates relationship automatically which we would not like to(İf in the setting auto relationship is open). I don't understand what exactly you would like to do but shoudn't be thinking relationship is same as merge. Relationship is like a filter context.

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

 

Anonymous
Not applicable

Hi @uzuntasgokberk , 

Wow! Thanks for the quick comment! 

So I want these to automatically form based on the relationship structure defined in the SQL schema because I want users that import this data to have as little work to do as possible in figuring out the relationships by themselves. 

Hello @Anonymous,

İt is not recommend way. Even Power BI makes relationship automatically that can be wrong relationships sometimes. Therefore, this is the best way if you make relationship manually. Because you know where you made relationship before creating reports.

Kind Regards,
Gökberk Uzuntaş

📌 If this post helps, then please consider Accepting it as a solution and giving Kudos — it helps other members find answers faster!

🔗 Stay Connected:
📘 Medium |
📺 YouTube |
💼 LinkedIn |
📷 Instagram |
🐦 X |
👽 Reddit |
🌐 Website |
🎵 TikTok |

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.