-
Notifications
You must be signed in to change notification settings - Fork 550
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
Upsert Problem on Multiple Columns Unique Key (MySQL) #328
Comments
I find it is because sqlboiler/drivers/sqlboiler-mysql/driver/mysql.go Lines 195 to 203 in 84770d2
@aarondl |
Hi @ceshihao. This is actually a pretty big problem. The idea of uniqueness in sqlboiler is based on single columns but that's of course not the only possible unique constraint inside a database. We may have to change the way we do uniques and instead make it a list of lists of columns. I'm trying to understand how this would affect the rest of sqlboiler's code. Obviously mysql's upsert would change. Some of the relationship stuff looks for unique and that would change too. I'll have to take a closer look and see what the tradeoffs are here. Worst case you should be able to fall back to raw queries here as a workaround temporarily. It's on my radar. :) |
After a quick investigation, I think mysql Upsert can still use The problem is mentioned in #177. If insert conflict and update the existing row to its current values (dummy update), Mentioned in https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
But I find a workaround to use a dummy column in update which can resolve the problem.
|
This is awkward. Thanks mysql :(
This might be useful. Just noting it here. The meat of this issue however is how sqlboiler views unique indexes. Currently it doesn't actually understand them correctly. It looks at a column individually and checks if it's unique. So the entire data model for it is wrong. Right now for our purposes it mostly works because the only real important thing about unique columns from sqlboiler's perspective is foreign keys. And since it rarely makes sense to have a composite unique index around a foreign key we don't run into problems other than this one. So it's not an easily fixable thing and because this is |
I would be glad to see this fixed. |
@cad: I don't really have a workaround to keep mysql Upsert working atm. Simply use a transaction and do a select and then an insert to deal with the problem. |
I am reviving this issue as it's still relevant. |
I don't think anything particular has changed. If you send in a PR for this, I would be happy to review/merge. Just remember that we cannot break backwards compatibility, so instead of changing the |
Upsert()
returns a errorcannot upsert with a table that cannot conflict on a unique column
.What version of SQLBoiler are you using (
sqlboiler --version
)?SQLBoiler v3.0.0-rc9
If this happened at runtime what code produced the issue? (if not applicable leave blank)
Yes
Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)
Further information. What did you do, what did you expect?
Upsert()
can work well with Multiple Columns Unique Key.After a quick investigation, I find the error is from
The text was updated successfully, but these errors were encountered: