| name | ha-config-migration |
| description | Config entry version migration in Home Assistant. Use when incrementing VERSION or MINOR_VERSION, implementing async_migrate_entry, or migrating stored entry data between schema versions. |
Home Assistant — Config Entry Version Migration
When your config entry schema changes (renaming keys, adding required fields, restructuring data), increment VERSION and implement async_migrate_entry.
Incrementing Versions
class MyConfigFlow(ConfigFlow, domain=DOMAIN):
VERSION = 2
MINOR_VERSION = 1
async_migrate_entry Template
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Migrate old entry to new version."""
_LOGGER.debug("Migrating from version %s.%s", entry.version, entry.minor_version)
if entry.version > 2:
return False
if entry.version == 1:
new_data = {**entry.data}
if "old_key" in new_data:
new_data["new_key"] = new_data.pop("old_key")
if "new_field" not in new_data:
new_data["new_field"] = "default_value"
hass.config_entries.async_update_entry(
entry, data=new_data, version=2, minor_version=0
)
if entry.version == 2 and entry.minor_version < 1:
new_options = {**entry.options}
new_options.setdefault("new_option", True)
hass.config_entries.async_update_entry(
entry, options=new_options, minor_version=1
)
_LOGGER.info("Migration to version %s.%s successful", entry.version, entry.minor_version)
return True
Rules
- Major VERSION (
VERSION = 2): Breaking changes — existing users' data must be transformed
- MINOR_VERSION (
MINOR_VERSION = 1): Non-breaking additions — safe to add defaults
- Return
True on success, False to signal migration failure (entry will be disabled)
- Guard against downgrades: if
entry.version is greater than the latest major VERSION this code supports, return False at the top. A higher-major entry means the user rolled HA/the integration back; old code cannot read the newer schema, so fail the migration cleanly (entry is disabled and surfaced) rather than letting it fall through to return True and load corrupt data silently
- Always log migration for debuggability
- Migrate incrementally through versions (1→2→3), not directly to latest
Related Skills
- Config flow →
ha-config-flow
- Deprecation fixes →
ha-deprecation-fixes