Closed simonw closed 1 year ago
I realized that I need this for Datasette Cloud, because the API and GraphQL API is much more interesting if you have foreign keys between things.
Also realized that I can suggest foreign keys (for tables smaller than a certain limit, I'll pick 10,000 for the moment) just by checking each column to see if it only contains values that exist as primary keys in another table - with a short-circuit so the moment you find a non-matching key you stop the search.
Got a prototype working. I'm going to ship that as an alpha, then add tests and docs later on.
Demo:
https://sqlite-utils.readthedocs.io/en/stable/python-api.html#adding-foreign-key-constraints