0

In pure SQL I can declare multiple foreign keys like:

ALTER TABLE available_routes  ADD FOREIGN KEY (client_id, site_id) REFERENCES sites(client_id, id);

I am trying to create model, that have some constrains. But can't understand how to do it:

mytable = Table ('mytable', metadata,
#...
Column('client_id', ForeignKey("clients.id"))
)
Yserbius
  • 1,375
  • 12
  • 18
Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145
  • For which purpose you want to create model ? if you want to add constrains then I will help you, will provide you full sql statement along with foreign key and constrains, please specify requirements – Aman Prajapati Apr 05 '18 at 13:28
  • It's a foreign key to a composite key, not "multiple foreign keys". That'd be multiple separate foreign keys. – Ilja Everilä Apr 05 '18 at 13:35
  • Since you're using `Table` instead of a mapped class this is not quite an exact duplicate, but you'll find the answer here: [Relations on composite keys using sqlalchemy](https://stackoverflow.com/questions/7504753/relations-on-composite-keys-using-sqlalchemy) – Ilja Everilä Apr 05 '18 at 13:50

0 Answers0