{"html_url": "https://github.com/simonw/sqlite-utils/issues/594#issuecomment-1714920708", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/594", "id": 1714920708, "node_id": "IC_kwDOCGYnMM5mN50E", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-09-12T03:51:13Z", "updated_at": "2023-09-12T03:51:13Z", "author_association": "OWNER", "body": "Changing this without breaking backwards compatibility (and forcing a 4.0 release) will be tricky, because `ForeignKey()` is a `namedtuple`:\r\n\r\nhttps://github.com/simonw/sqlite-utils/blob/622c3a5a7dd53a09c029e2af40c2643fe7579340/sqlite_utils/db.py#L148-L150\r\n\r\nI could swap it out for a `dataclass` and add those extra columns, but I need to make sure that code like this still works:\r\n```python\r\nfor table, column, other_table, other_column in table.foreign_keys:\r\n # ...\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1891614971, "label": "Represent compound foreign keys in table.foreign_keys output"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/594#issuecomment-1714919806", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/594", "id": 1714919806, "node_id": "IC_kwDOCGYnMM5mN5l-", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-09-12T03:49:41Z", "updated_at": "2023-09-12T03:49:41Z", "author_association": "OWNER", "body": "Digging in a bit more:\r\n```pycon\r\n>>> pprint(list(db.query('PRAGMA foreign_key_list(courses)')))\r\n[{'from': 'campus_name',\r\n 'id': 0,\r\n 'match': 'NONE',\r\n 'on_delete': 'NO ACTION',\r\n 'on_update': 'NO ACTION',\r\n 'seq': 0,\r\n 'table': 'departments',\r\n 'to': 'campus_name'},\r\n {'from': 'dept_code',\r\n 'id': 0,\r\n 'match': 'NONE',\r\n 'on_delete': 'NO ACTION',\r\n 'on_update': 'NO ACTION',\r\n 'seq': 1,\r\n 'table': 'departments',\r\n 'to': 'dept_code'}]\r\n```\r\nI think the way you tell it's a compound foreign key is that both of those have the same `id` value - of `0` - but they then have two different `seq` values of `0` and `1`.\r\n\r\nRight now I ignore those columns entirely: https://github.com/simonw/sqlite-utils/blob/622c3a5a7dd53a09c029e2af40c2643fe7579340/sqlite_utils/db.py#L1523-L1540", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1891614971, "label": "Represent compound foreign keys in table.foreign_keys output"}, "performed_via_github_app": null}