{"record":{"id":"777b9e95b0b4d63b","repo":"invoke-ai/InvokeAI","slug":"a-model-with-path-config-path-is-already-insta","errorCode":null,"errorMessage":"A model with path '{config.path}' is already installed","messagePattern":"A model with path '(.+?)' is already installed","errorType":"exception","errorClass":"DuplicateModelException","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/model_records/model_records_sql.py","lineNumber":139,"sourceCode":"                        config\n                        )\n                    VALUES (?,?);\n                    \"\"\",\n                    (\n                        config.key,\n                        config.model_dump_json(),\n                    ),\n                )\n\n            except sqlite3.IntegrityError as e:\n                if \"UNIQUE constraint failed\" in str(e):\n                    if \"models.path\" in str(e):\n                        msg = f\"A model with path '{config.path}' is already installed\"\n                    elif \"models.name\" in str(e):\n                        msg = f\"A model with name='{config.name}', type='{config.type}', base='{config.base}' is already installed\"\n                    else:\n                        msg = f\"A model with key '{config.key}' is already installed\"\n                    raise DuplicateModelException(msg) from e\n                else:\n                    raise e\n\n        return self.get_model(config.key)\n\n    def del_model(self, key: str) -> None:\n        \"\"\"\n        Delete a model.\n\n        :param key: Unique key for the model to be deleted\n\n        Can raise an UnknownModelException\n        \"\"\"\n        with self._db.transaction() as cursor:\n            cursor.execute(\n                \"\"\"--sql\n                DELETE FROM models\n                WHERE id=?;","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/model_records/model_records_sql.py#L121-L157","documentation":"add_model inserts a new model config into the SQLite models table; on an integrity error it inspects the constraint name and raises DuplicateModelException when another record already occupies the same path (unique constraint on models.path). The message reports the conflicting path.","triggerScenarios":"Calling add_model with a config whose path matches an already-installed model — installing a second copy from the same directory, or re-adding a scanned model without dedupe by path.","commonSituations":"Multiple scan directories containing the same model; re-running an install job after a partial failure that already recorded the record; pointing a new model entry at a shared folder like autoimport with duplicates.","solutions":["Get the existing record via search_by_path and reuse/update it instead of adding a new one.","Delete the existing model entry if it is stale, then re-add.","Change the new model's path (or the underlying file location) so it is unique.","Update the existing record with update_model instead of insert."],"exampleFix":"# before\nrecords.add_model(config_with_path_already_installed)\n# after\nexisting = records.search_by_path(path=config.path)\nif existing:\n    records.update_model(existing[0].key, changes)\nelse:\n    records.add_model(config)","handlingStrategy":"validation","validationCode":"existing = records.search_by_path(path=config.path)\nif existing:\n    raise ValueError(f\"Path {config.path} already installed as key {existing[0].key}\")","typeGuard":null,"tryCatchPattern":"try:\n    records.add_model(config)\nexcept DuplicateModelException as e:\n    if f\"path '{config.path}'\" in str(e):\n        old = records.search_by_path(config.path)[0]\n        records.update_model(old.key, changes)\n    else:\n        raise","preventionTips":["Check search_by_path before installing a path-based model","Avoid scanning the same directory twice via multiple scan roots","Treat install failures idempotently — retry as update, not insert"],"tags":["duplicate-model","unique-constraint","sqlite","model-records"],"backgroundTag":"duplicate-model-path","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}