Skip to main content
You can expect the schemas in your Agno database tables to be stable across versions. However, in future versions, we may occasionally update or add new columns or tables. If you need to apply a migration, you can use the MigrationManager class:
import asyncio

from agno.db.migrations import MigrationManager
from agno.db.postgres import AsyncPostgresDb

# The database you want to migrate
db = AsyncPostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

async run_migrations():
    await MigrationManager(db).up()

if __name__ == "__main__":
    asyncio.run(run_migrations())
You can find some pre-made scripts to handle your migration needs in the libs/agno/migrations directory.

Reverting Migrations

You can also use the MigrationManager class to revert a migration:
import asyncio

from agno.db.migrations import MigrationManager
from agno.db.postgres import AsyncPostgresDb

# The database you want to migrate
db = AsyncPostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

async run_revert_migrations():
    await MigrationManager(db).down(target_version="2.0.0")

if __name__ == "__main__":
    asyncio.run(run_revert_migrations())

Migrating a Specific Table

In case you need it, notice you can migrate only a specific table:
import asyncio

from agno.db.migrations import MigrationManager
from agno.db.postgres import AsyncPostgresDb

# The database you want to migrate
db = AsyncPostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

async run_migrate_table():
    # This will migrate the memories table to the latest version
    await MigrationManager(db).up(table_type="memory")

if __name__ == "__main__":
    asyncio.run(run_migrate_table())
The supported table types are: session, memory, metrics, eval, knowledge, culture.

Support for Other Databases

The MigrationManager class supports the following databases:
  • PostgreSQL
  • SQLite
  • MySQL
  • SingleStore
You can also use the asynchronous database classes (AsyncPostgresDb and AsyncSqliteDb) with your migrations.

Migrating from Agno v1 to v2

If you started using Agno during its v1 and want to move to v2, we have a migration script that can help you update your database tables. You can find the script in the libs/agno/migrations/v1_to_v2/migrate_to_v2.py file. You can find more information about migrating from v1 to v2 in the Migrating to Agno v2 guide.