Registry / database / peewee-migrate

peewee-migrate

JSON →
library1.15.0pypypi✓ verified 85d ago

Peewee-migrate, currently at version 1.15.0, provides robust database migration support for the Peewee ORM. It enables developers to manage schema changes through versioned migrations, offering features like creation, application, and rollback of migrations. The library is actively maintained on GitHub with a regular release cadence, ensuring compatibility and ongoing improvements for Peewee projects.

pip install peewee-migrate
INSTALL
IMPORT
SIG · PEEWEE-MIGRATE
P
peewee-migrate
databasepythonv1.15.0
Install
1.8s avg
Import
441ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.15.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.478s · 20.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.404s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Router
from peewee_migrate import Router

This quickstart demonstrates how to initialize the `Router` with a Peewee database and run migrations. It sets up a dummy migration directory and file for the example to be runnable. In a real application, you would create migration files using `router.create()` and then manually define your schema changes within them.

import os from peewee import * from peewee_migrate import Router # 1. Initialize a Peewee database instance db = SqliteDatabase('example.db') # 2. Define the directory where your migration files are stored migrations_dir = 'my_migrations' # Create a dummy migration directory and file for the example to be runnable os.makedirs(migrations_dir, exist_ok=True) with open(os.path.join(migrations_dir, '001_initial.py'), 'w') as f: f.write('from peewee import *\ndef migrate(migrator, database, **kwargs):\n pass\ndef rollback(migrator, database, **kwargs):\n pass') # 3. Initialize the Peewee-Migrate Router router = Router(db, migrate_dir=migrations_dir) # 4. Run all pending migrations # In a real scenario, you would have migration files in 'my_migrations' # defining schema changes. print("Running migrations...") router.run() print("Migrations completed successfully.") # Clean up created files/dirs for a repeatable example if os.path.exists('example.db'): os.remove('example.db') if os.path.exists(migrations_dir): import shutil shutil.rmtree(migrations_dir)
pw_migrate --version
Debug
Known issues
breakingThe `Router` constructor signature changed significantly in version 1.0.0. The second positional argument (path to migrations) was removed in favor of a keyword argument `migrate_dir`.
fix
Update `Router(db, '/path/to/migrations')` to `Router(db, migrate_dir='/path/to/migrations')`.
affects: >=1.0.0 (breaking change from <1.0.0)
gotchaMigration files must adhere to the `NNN_name.py` naming convention (e.g., `001_create_user_table.py`) and be placed in the `migrate_dir` specified to the `Router` instance. Files not following this format or placed elsewhere will be ignored.
fix
Ensure migration files are named `NNN_descriptive_name.py` and located in the directory passed via `migrate_dir`.
affects: All versions
gotchaRollback functions (`rollback(migrator, database, **kwargs)`) are optional but highly recommended. If a `rollback` function is not provided for a `migrate` operation, that specific migration cannot be reversed using `peewee-migrate`'s rollback command.
fix
Always implement a corresponding `rollback` function that effectively reverses the changes made by its `migrate` counterpart. For example, `migrator.add_model()` in `migrate` should be paired with `migrator.remove_model()` in `rollback`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'peewee'
The 'peewee' ORM library, a core dependency for 'peewee-migrate', is not installed in the current Python environment.
fix
Install the 'peewee' library using pip: `pip install peewee`
pw_migrate: command not found
The 'pw_migrate' command-line entry point, installed by 'peewee-migrate', is not accessible in the system's PATH, or the Python virtual environment where it was installed is not activated.
fix
Activate your Python virtual environment if you are using one. Alternatively, run the command using Python's module execution: `python -m peewee_migrate <command>`
peewee.InterfaceError: Error, database must be initialized before opening a connection.
The Peewee database object used by peewee-migrate was not properly initialized or connected before a migration operation was attempted.
fix
Ensure your Peewee database instance (e.g., `SqliteDatabase`, `PostgresqlDatabase`) is explicitly initialized and connected before passing it to `peewee_migrate.Router` or using it in migration scripts. If using a `Proxy` object, call `database_proxy.initialize(actual_database_instance)`.
Can't import models module
When using `pw_migrate create --auto-source <module_path>`, the specified Python module path where your Peewee models reside cannot be imported by 'peewee-migrate', often due to an incorrect path or the module not being discoverable in `PYTHONPATH`.
fix
Ensure the `--auto-source` argument provides a valid, importable Python module path (e.g., `my_app.models`) and that the directory containing this module is correctly in your `PYTHONPATH` or that you are running `pw_migrate` from the project's root directory.
Upgrade
Version history
1.15.0latest on PyPI · released Mar 12, 2026
Audit
Dependencies
peeweerequiredCore ORM that peewee-migrate extends for database migrations.
Agent activity
42 hits · last 30 days
node
36
Amazon
1
OpenAI (training)
1
Resources
peewee-migrate — pip install peewee-migrate · libregistry