Jack
Jack

Reputation: 1437

Django - how to export and import user data for database migration?

I am moving my website to another cloud server for delpoying, so I have to export all the user information (account name, password, accounts.profile from the existing database, then import to the new website hosted by the new server.

I have tried to export user data using default: python manage.py dumpdata > users.json the users.json looks like:

[{"model": "accounts.profile", "pk": 1, "fields": {"user": 2, "telephone": "0755-25187181", "company_name": "watchtech"}}, {"model": "accounts.profile", "pk": 2, "fields": {"user": 3, "telephone": "18696511023", "company_name": "King's Machinery"}},....}}]

I noticed there is no password information exported. when I use "python manage.py loaddata user.json", how to ensure it also loads the password of users, so that users can login the new website?

UPDATE - please note that I have applied "accounts.profile" model in addition to the default user model, to include more fields of user information.

from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver


class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True, null=True)
    telephone = models.TextField(blank=True, null=True)
    company_name = models.TextField(blank=True, null=True)

this is the CMD I used to export both the user and order data from the original database, which result in two json files.

source myvenv/bin/activate; python3.6 manage.py dumpdata accounts>DB_backup/user_backup.json
source myvenv/bin/activate; python3.6 manage.py dumpdata OnlinePricing>DB_backup/order_backup.json

Upvotes: 0

Views: 643

Answers (1)

JanMalte
JanMalte

Reputation: 1050

Create a real database dump using your database management tools.

dumpdata and loaddata are not intended to move a complete website.

The posted part of your dump is just the accounts.profile model data. The user data (username, password hash, email, ...) belong to another model in your application and therefore are somewhere later in your users.json.

Upvotes: 0

Related Questions