I am working with SQLAlchemy and I have a table I want to add, order
, which references a currency table.
I want a foreign key relationship setup so the order points to a currency in the currency table, but I don't want the currency table to contain a list of orders which use that currency. Most of the docs make me think that relationships go two ways, but I want something that is more one directional, that match raw SQL like:
CREATE TABLE order ... FOREIGN KEY(currency_id) REFERENCES currencies(id)
Is this possible with SQLAlchemy?
Simply don't define a relationship on the other end, in your case "currency", and don't use backref
. Relationships are actually unidirectional by default and you have to use back_populates
etc. in order to make them bidirectional. This is covered in "Basic Relationship Patterns".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With