{"html_url": "https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968359137", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/335", "id": 968359137, "node_id": "IC_kwDOCGYnMM45t_zh", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-14T20:37:00Z", "updated_at": "2021-11-14T20:37:00Z", "author_association": "OWNER", "body": "This is strange - the code already checks that an index doesn't exist before attempting to create it: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L893-L902", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1042569687, "label": "sqlite-utils index-foreign-keys fails due to pre-existing index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968359868", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/335", "id": 968359868, "node_id": "IC_kwDOCGYnMM45t_-8", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-14T20:41:42Z", "updated_at": "2021-11-14T20:41:42Z", "author_association": "OWNER", "body": "The \"index idx_generators_eia860_report_date already exists\" error suggests that the problem here is actually one of an index name collision.\r\n\r\n```python\r\n table.create_index([fk.column]) \r\n```\r\nThis will derive a name for the index automatically from the name of the table and the name of the passed in columns: https://github.com/simonw/sqlite-utils/blob/92aa5c9c5d26b0889c8c3d97c76a908d5f8af211/sqlite_utils/db.py#L1536-L1539\r\n\r\nSo perhaps `.create_index()` should grow an extra option that creates the index even if the name already exists, by finding a new name.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1042569687, "label": "sqlite-utils index-foreign-keys fails due to pre-existing index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968360387", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/335", "id": 968360387, "node_id": "IC_kwDOCGYnMM45uAHD", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-14T20:45:44Z", "updated_at": "2021-11-14T20:45:44Z", "author_association": "OWNER", "body": "What would such an option be called? Some options:\r\n\r\n- `table.create_index([fk.column], force=True)` - not obvious what `force` means here\r\n- `table.create_index([fk.column], ignore_existing_name=True)` - not obvious what `ignore` means here\r\n- `table.create_index([fk.column], pick_unique_name=True)` - bit verbose\r\n\r\nIf the user doesn't pass in an explicit name it seems like their intent is \"just create me the index, I don't care what name you use\" - so actually perhaps the default behaviour here should be to pick a new unique name if that name is already in use.\r\n\r\nThen maybe there should be an option to disable that - some options there:\r\n\r\n- `table.create_index([fk.column], error_on_existing_index_name=True)` - too verbose\r\n- `table.create_index([fk.column], force=False)` - not clear what `force` means\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": 1042569687, "label": "sqlite-utils index-foreign-keys fails due to pre-existing index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968360538", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/335", "id": 968360538, "node_id": "IC_kwDOCGYnMM45uAJa", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-14T20:46:56Z", "updated_at": "2021-11-14T20:46:56Z", "author_association": "OWNER", "body": "I'm tempted to not provide an opt-out option either: if you call `table.create_index(...)` without specifying an index name I think the tool should create the index for you, quietly picking an index name that works.\r\n\r\nBut... it feels wasteful to create an index that exactly duplicates an existing index. Would SQLite even let you do that or would it notice and NOT double the amount of disk space used for that index?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1042569687, "label": "sqlite-utils index-foreign-keys fails due to pre-existing index"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/335#issuecomment-968361285", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/335", "id": 968361285, "node_id": "IC_kwDOCGYnMM45uAVF", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-11-14T20:51:57Z", "updated_at": "2021-11-14T20:51:57Z", "author_association": "OWNER", "body": "SQLite will happily create multiple identical indexes on a table, using more disk space each time:\r\n```pycon\r\n>>> import sqlite_utils\r\n>>> db = sqlite_utils.Database(\"dupes.db\")\r\n>>> db[\"t\"].insert_all({\"id\": i} for i in range(10000))\r\n