A query fails to create (in this example articles) because the set_id column (foreign key) is set to 0 and breaks the constraint. This happened, I think, because the previous query that inserts the sets returns not only the id, but also the column parent_code: ON CONFLICT DO NOTHING RETURNING "parent_code","id"
On MySQL the test passed.
This is strange behavior for an ORM library that which the same code works with a driver (MySQL) and fails with another (Postgresql).
This seems caused because in the field parent_code I have set the tag gorm:"default:(-)", that I cannot remove. And the fields with this kind of tag are returned in the RETURNING statement.
GORM Playground Link
https://github.com/go-gorm/playground/pull/458
Description
A query fails to create (in this example
articles
) because theset_id
column (foreign key) is set to 0 and breaks the constraint. This happened, I think, because the previous query that inserts thesets
returns not only theid
, but also the columnparent_code
:ON CONFLICT DO NOTHING RETURNING "parent_code","id"
On MySQL the test passed.
This is strange behavior for an ORM library that which the same code works with a driver (MySQL) and fails with another (Postgresql).