[odb-users] Create a foreign key constrain to a unique column of other table

Vassilios Kountouriotis b.kountouriotis at gmail.com
Fri Sep 15 09:53:33 EDT 2017

On Sep 15, 2017 3:05 PM, "Boris Kolpackov" <boris at codesynthesis.com> wrote:

Vassilios Kountouriotis <b.kountouriotis at gmail.com> writes:

> Yes, that would be my final "solution" but I would be giving up a part of
> what makes ODB magical: its support for schema evolution...

I am confused: if you have a custom schema and are not relying on ODB to
generate it, then I don't see how you could rely on ODB's schema evolution

I'm trying to have ODB generate exactly the schema I have.

Or are you trying to make ODB generate identical (to your custom) schema
and then use that as a strating point for any future changes?

Exactly this!!! 100%!!

> Might I suggest you consider such a feature for future releases? It would
> be really nice if we could specify constraints with pragmas as we can with
> the indexes...

Perhaps there is already a mechanism that will allow you to achieve this:
column options. See Section 14.4.8 for details

This seems to be in the direction I'd like but as I understand it this
appends the options into its column definition. So I would have to write
something like

#pragma db type("CHAR(36)") options("COLLATE utf8_bin, CONSTRAINT
`fkname_blahblahblah` FOREIGN KEY (`LogTicketID`) REFERENCES `Ticket`
std::string LogTicketID;

Which works as intended although it is a bit "manual" still.
One question I have concerning the above is, will any change in the
options("...") trigger any data loss? (Column dropped and re-added with new


More information about the odb-users mailing list