pip install django-wordpress
python
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'wordpress',
'USER': 'mysql_username',
'PASSWORD': 'mysql_password',
'HOST': 'localhost',
'PORT': '3306',
}
}
python manage.py startapp wordpress_migration
python
INSTALLED_APPS = [
...
'wordpress_migration',
...
]
python manage.py makemigrations wordpress_migration
python
from django.db import migrations
from wordpress.models import Post
def migrate_posts(apps, schema_editor):
SourcePost = apps.get_model('wordpress', 'Post')
DestinationPost = apps.get_model('wordpress_migration', 'Post')
for source_post in SourcePost.objects.all():
destination_post = DestinationPost()
destination_post.title = source_post.title
destination_post.content = source_post.content
destination_post.save()
class Migration(migrations.Migration):
dependencies = [
('wordpress', '0001_initial'),
('wordpress_migration', '0001_initial'),
]
operations = [
migrations.RunPython(migrate_posts),
]
python manage.py migrate wordpress_migration
python manage.py dumpdata wordpress --exclude auth.permission --exclude contenttypes > backup.json