Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error retrieving constraints from MySQL schema #57

Open
ricardoolsen opened this issue Feb 1, 2024 · 2 comments
Open

Error retrieving constraints from MySQL schema #57

ricardoolsen opened this issue Feb 1, 2024 · 2 comments

Comments

@ricardoolsen
Copy link

Hi! Thanks for this useful tool.

I have encountered error retrieving constraints from a MySQL schema.

I was able to fix it by adding "limit 1" to a subquery from /database/mysql.go (line 149).

(
select kc2.CONSTRAINT_NAME is not null "isPrimary"
from information_schema.KEY_COLUMN_USAGE kc
left join information_schema.KEY_COLUMN_USAGE kc2
			ON kc.COLUMN_NAME = kc2.COLUMN_NAME AND kc2.CONSTRAINT_NAME = 'PRIMARY' AND
			kc2.TABLE_NAME = kc.TABLE_NAME
         where kc.CONSTRAINT_NAME = c.CONSTRAINT_NAME and kc.COLUMN_NAME = kcu.COLUMN_NAME limit 1
) "isPrimary",

The error occured because the subquery was returning more than one row in my case.
Best regards.

@KarnerTh
Copy link
Owner

KarnerTh commented Feb 2, 2024

Thanks for the ticket!
Can you provide the DDL/schema that causes the error? If I can reproduce the error I can investigate the issue in more detail.

@ricardoolsen
Copy link
Author

Hi Karner!

I'm sorry, I cant't share it because it is an enterprise schema, not to be shared.

The schema has lots of relationships and constraints.

It has double foreign keys like two columns of the same table pointing to columns on another table. I think this can be the cause of the problem.

It has also a recursive relation: a colunm pointing to another on the same table.

Otherwise it is pretty normal stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants