-
Notifications
You must be signed in to change notification settings - Fork 552
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
Ignore tables without a primary key #75
Comments
Hi. What database are you using? I'd wager there would be query you could do to return that list of tables to feed into the white list or black list. Anyway, to answer your question, this not something we currently support through a flag like that. Our reasoning for the error is that we rely on the existence of primary keys to generate your relationships properly and in reality every table should have a primary key and a failed generation is a good reminder that the database schema needs to be adjusted. I realize this is a bit of a nuisance in your case since you're dealing with a legacy system. @aarondl what are your thoughts? |
So my thoughts are somewhat along the same lines. I wonder what the real use case is. SQLBoiler has SIGNIFICANTLY reduced functionality when you don't have a primary key, and as such we don't even generate structs for them. To workaround this issue you can:
We could probably make this work by changing a lot of the templates to ignore tables without a primary key. It would probably only be able to generate a struct, since even insert/update/delete/find is all ID based. It could also do select I suppose. Can you tell us more about this use case? And why you can't change the database? |
Hi, I'm working on a large legacy system based on MySQL(old version too...). There are many foreign keys across hundreds of tables, and some of them are missing primary keys and violating regular thinkings on the schema design. i.e. below example shows a common use case in this legacy system.
And yes, sometimes, blacklist/whitelist are helpful to this kind cases, but it could be a blocker when generating models against tables(a whitelist created on foreign keys constraints) without primary keys. |
We've decided we're not going to support tables without primary keys still. It really ruins any advantage you're getting from using sqlboiler. For dealing with legacy databases I suggest things like: I'd also consider a pull request if it were clean enough. Or if enough people ask for this I may reconsider. |
Hi, I have a DB with Read-only access. There are 20 to 30 tables in it and I need data from 5 tables which have primary keys in it. I like to use sqlboiler and I am trying to generate models and getting no primary key error. Is there any way that I can handle this ? |
It would probably work if you whitelisted the tables you needed. |
My use case: I would like to create a view that will not be used by golang code. Right now sqlboiler is complaining that the view is missing a primary key; I would like to tell sqlboiler to not worry about the view. Seems like having sqlboiler know to skip this view would be a reasonable thing. |
Yep. Blacklisting or Whitelisting tables should work? |
Either should do the trick in my case. (I see now that there is table whitelisting and blacklisting.) |
Will sqlboiler allow ignoring tables without a primary key?
Asking this because I'm working with a large legacy system with hundreds of tables and complicated foreign key settings.
So it's difficult for me to provide a correct whitelist, and I have to generate the orm agaist the whole schema.
I guess a "--ignore-tables-without-primary-keys" may help this kind of usage.
The text was updated successfully, but these errors were encountered: