Created
March 25, 2025 21:36
-
-
Save mathjazz/e64d69687e118b3cdc9bf7c706cc3008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Yes, you *can* import data from your local **SQLite** database into your **production PostgreSQL** database in a **Django + Wagtail** app — but you’ll need to be careful, especially with things like IDs, foreign keys, and data integrity. | |
Here’s a breakdown of your options and steps: | |
--- | |
## ✅ Option 1: Use `manage.py dumpdata` + `loaddata` | |
### Step 1: Dump the data from SQLite | |
On your **local machine**, run: | |
```sh | |
python manage.py dumpdata --exclude=contenttypes --exclude=auth.permission --indent=2 > local_data.json | |
``` | |
> You can filter by app too: `dumpdata myapp.ModelName`. | |
This creates a portable JSON file of your data. | |
### Step 2: Clean the file (optional but recommended) | |
- Check for model differences between environments | |
- Make sure file sizes are reasonable | |
- Remove anything you don't want imported (like test users) | |
### Step 3: Load into PostgreSQL (production) | |
**‼️ WARNING:** This can overwrite data and should not be done blindly on prod. Ideally: | |
- Test on a **staging environment first** | |
- Back up your production DB before importing | |
Then run: | |
```sh | |
python manage.py loaddata local_data.json | |
``` | |
> Note: This may fail if there are PK clashes or constraints not met in Postgres (e.g., stricter data types). | |
--- | |
## ⚠️ Option 2: Use Django fixtures per app or model | |
To avoid importing *everything*, do this per model: | |
```sh | |
python manage.py dumpdata myapp.ModelName > mymodel.json | |
python manage.py loaddata mymodel.json | |
``` | |
This helps avoid breaking core Wagtail or Django tables. | |
--- | |
## 🔁 Option 3: Migrate content via Wagtail's Export/Import | |
If you’re mostly moving **pages or Wagtail-specific content**, check out: | |
- [`wagtail-import-export`](https://github.com/wagtail/wagtail-import-export) | |
- Custom scripts using Wagtail's API to export and recreate pages | |
--- | |
## 🧠 Tips & Best Practices | |
- Avoid touching `auth` and `admin` related models unless you know what you're doing | |
- Clean out local-only or development data before importing | |
- Consider using a **PostgreSQL local DB** for future development to avoid format mismatch | |
--- | |
Want help writing a script or handling a specific app/model’s migration? I’ve got you. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment