invoke-ai/InvokeAI · error · UnknownModelException
model not found
Error message
model not found
What it means
del_model deletes the row with the given key from the models table; if the DELETE affects zero rows it raises UnknownModelException('model not found'). It guarantees delete operations fail loudly rather than silently no-op on a stale key.
Source
Thrown at invokeai/app/services/model_records/model_records_sql.py:162
def del_model(self, key: str) -> None:
"""
Delete a model.
:param key: Unique key for the model to be deleted
Can raise an UnknownModelException
"""
with self._db.transaction() as cursor:
cursor.execute(
"""--sql
DELETE FROM models
WHERE id=?;
""",
(key,),
)
if cursor.rowcount == 0:
raise UnknownModelException("model not found")
def update_model(self, key: str, changes: ModelRecordChanges, allow_class_change: bool = False) -> AnyModelConfig:
with self._db.transaction() as cursor:
record = self.get_model(key)
if allow_class_change:
# The changes may cause the model config class to change. To handle this, we need to construct the new
# class from scratch rather than trying to modify the existing instance in place.
#
# 1. Convert the existing record to a dict
# 2. Apply the changes to the dict
# 3. Attempt to create a new model config from the updated dict
# 1. Convert the existing record to a dict
record_as_dict = record.model_dump()
# 2. Apply the changes to the dict
for field_name in changes.model_fields_set:View on GitHub (pinned to 0b6a024f2f)
Solutions
- Check existence with get_model/search before deleting, or catch UnknownModelException and treat it as already-deleted success (idempotent delete).
- Refresh the model list to obtain current keys.
- Verify you are operating on the intended InvokeAI database/root directory.
Example fix
# before
records.del_model(key) # UnknownModelException on second run
# after
try:
records.del_model(key)
except UnknownModelException:
pass # already deleted; idempotent Defensive patterns
Strategy: try-catch
Validate before calling
def safe_del(records, key) -> bool:
try:
records.get_model(key)
except UnknownModelException:
return False
records.del_model(key)
return True Try / catch
try:
records.del_model(key)
except UnknownModelException:
log.info('Model %s already deleted; treating as success', key) Prevention
- Make deletes idempotent by ignoring UnknownModelException where appropriate
- Fetch keys immediately before deleting; do not cache across long runs
- Serialize delete operations to avoid racing double-deletes
- Confirm the InvokeAI root/DB you are operating on matches the UI
When it happens
Trigger: Calling del_model(key) with a key that was already deleted, never existed, or from a different database; racing concurrent deletes (two requests deleting the same model); using a key from a stale cached config.
Common situations: Double-clicking delete in the UI issuing two requests; automation scripts deleting models whose keys were fetched earlier in the run; pointing at a different DB file than expected (wrong InvokeAI root).
Related errors
- Model '{body.model_key}' not found
- Failed to delete video
- Unknown lora: {lora_key}!
- Unknown lora: {lora_key}!
- Unknown lora: {lora.lora.key}!
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/8d6053a79013fd26.
Report an issue: GitHub.