Documentation Index
Fetch the complete documentation index at: https://docs.cognee.ai/llms.txt
Use this file to discover all available pages before exploring further.
cognee.run_startup_migrations
Applies all pending database schema migrations before the rest of your application starts.- Relational schema — executes
alembic upgrade headagainst your configured relational database (SQLite by default, or Postgres). - Vector schema — runs the vector adapter’s
run_migrationsmethod for every database that needs it:- Single-user mode (
ENABLE_BACKEND_ACCESS_CONTROL=False): migrates the single default vector engine. - Multi-user mode (
ENABLE_BACKEND_ACCESS_CONTROL=True, the default): iterates over every dataset database and migrates each one individually. A failure for one dataset is logged and skipped; the remaining datasets continue to migrate. - If the active vector engine has no
run_migrationsmethod, Cognee logs a warning and skips that engine.
- Single-user mode (
When to call it
| Scenario | Why |
|---|---|
After upgrading the cognee package | New versions may add tables or columns to the relational schema. |
| First run against an external database | SQLite is auto-migrated on startup; Postgres and other external databases are not. |
| Kubernetes / Docker init containers | Run migrations once before starting the main application pods. |
| Switching to a new relational DB provider | The new database starts empty and needs all migrations applied. |
For the default local setup (SQLite + LanceDB), Cognee handles migrations automatically when the API server starts. You only need to call
run_startup_migrations() explicitly in server deployments or CI pipelines where you manage database lifecycle yourself.Example
Kubernetes init container
Run migrations as a one-shot init container so the main pod only starts after the schema is ready:Errors
| Error | Cause | Fix |
|---|---|---|
FileNotFoundError | alembic.ini or the migrations directory is missing from the installed package. | Reinstall cognee — the package may be corrupted or partially installed. |
MigrationError | Alembic exited with a non-zero return code. | Check the error message logged at ERROR level; usually a DB connection problem or a SQL conflict. |
Related
- Relational Databases — configure SQLite or Postgres
- Deployment Overview — how to structure Cognee in production
- Kubernetes (Helm) — full Kubernetes deployment guide