This project contains a simple Python script for migrating all records from one PocketBase collection to the same collection in another PocketBase database.
The script assumes both PocketBase databases already contain the same collection with the same fields.
- Prompts for a source PocketBase URL
- Prompts for a destination PocketBase URL
- Prompts for the collection name to migrate
- Prompts for superuser credentials for both PocketBase databases
- Fetches all records from the source collection
- Creates those records in the destination collection
- Does not delete or overwrite existing destination records
- Python 3
- Superuser or admin access to both PocketBase databases
- The collection must already exist in both databases
- The collection schema should be the same in both databases
No extra Python packages are required.
Before running the migration script, make sure the destination PocketBase database has the same collection schema as the source database.
You can copy the collection structure through the PocketBase admin UI:
- Open the source PocketBase admin dashboard.
- Go to
Settings. - Click
Export Collections. - Select the collection/table you want to migrate.
- Copy the exported JSON.
- Open the destination PocketBase admin dashboard.
- Go to
Settings. - Click
Import Collections. - Paste the copied JSON.
- Click
Review. - Import the collection from there.
After the collection exists in the destination database, run the migration script to copy the records.
From the project folder, run:
python3 migrate_collection.pyThis is an anonymized example showing what a successful migration looks like.
user@MacBook PB_Migration % python3 migrate_collection.py
PocketBase collection migration
This creates records in the destination collection; it does not delete existing records.
File upload fields are not migrated by this simple script.
Source PocketBase URL: https://source-pocketbase.example.com/
Destination PocketBase URL: https://destination-pocketbase.example.com/
Collection name to migrate: domains
Source superuser credentials
Email: source-admin@example.com
Password:
Destination superuser credentials
Email: destination-admin@example.com
Password:
Preserve source record IDs [Y/n]: y
Authenticating...
Fetching source records...
Found 21 record(s).
Press Enter to start migration...
Migrated 21/21
Migration complete: 21 record(s) migrated in 2.8s.- Password input is hidden while typing.
- Choosing
yforPreserve source record IDskeeps the same record IDs in the destination database. - If the destination database already contains records with the same IDs, PocketBase may reject those records.
- File upload fields are not migrated by this simple script.
- Existing records in the destination collection are not removed.