Milano Slesarik Milano Slesarik - 1 month ago 5
Python Question

How to export and import data and auth information in Django?

I'm working on a project which is already public so there are some Order objects and User objects in the database (couple of people has registrated and created some orders).

Now I'm changing some things in this project including Order model (added some fields like


So my new database (sqlite3) has very similar schemas compared to old but it's not the same.

How can I add old users and Order objects into the new db? Is there some plugin or best practise?

There should be no problem with Users because their schema hasn't changed but I suppose that
table is not enough to copy.

class Order(models.Model):
customer = models.ForeignKey(User, related_name='orders', blank=True, null=True)
first_name = models.CharField(max_length=40,verbose_name=u'Vorname')
last_name = models.CharField(max_length=40,verbose_name=u'Nachnahme')
dry_wood = models.PositiveIntegerField(blank=True, null=True, default=0,verbose_name=u'Trockenes Holz')
wet_wood = models.PositiveIntegerField(blank=True, null=True, default=0,verbose_name=u'Halb trockenes Holz')
briquette = models.PositiveIntegerField(blank=True, null=True, default=0,verbose_name=u'Brikettes')
stelinka = models.PositiveIntegerField(blank=True, null=True, default=0,verbose_name=u'Klein Holz')
street = models.CharField(max_length=200, verbose_name=u'Straße', null=True, blank=True)
number = models.CharField(max_length=40, null=True, blank=True, verbose_name=u'Hausnummer')
city = models.CharField(max_length=100, verbose_name=u'Stadt', null=True, blank=True)
psc = models.CharField(max_length=40, null=True, blank=True, verbose_name=u'PLZ')
telephone = models.CharField(max_length=50, null=True, blank=True, verbose_name=u"Telefon Nummer")
telephone2 = models.CharField(max_length=50, null=True, blank=True, verbose_name=u'Telefon 2')

email = models.EmailField(null=True, blank=True,verbose_name=u'Mail')
time = models.TextField(null=True, blank=True, verbose_name=u'Kommentar')
price = models.DecimalField(max_digits=20, decimal_places=2, blank=True, null=True)
text_order = models.TextField(blank=True, null=True, verbose_name=u'Kommentar')
confirmed = models.BooleanField(default=False, verbose_name=u'Potvrdená zákazníkom')
done = models.BooleanField(default=False, verbose_name=u'Vybavená')
TYPE_CHOICES = (('wholesale', u'Veľkoodber'),
('retail', u'Maloodber'))
type = models.CharField(max_length=40, choices=TYPE_CHOICES, default='retail')

created = models.DateTimeField(auto_now_add=True, blank=True, null=True)

LENGTH_OF_DRY_WOOD_CHOICES = (('1.0','1.0'),
('0.5', '0.5'),
('0.33', '0.33'),
('0.25', '0.25'))

LENGTH_OF_WET_WOOD_CHOICES = (('1.0','1.0'),
('0.5', '0.5'),
('0.33', '0.33'),
('0.25', '0.25'))

length_of_dry_wood = models.CharField(max_length=40, choices=LENGTH_OF_DRY_WOOD_CHOICES, default='0.5', null=True, blank=True,verbose_name=u'Länge des Holzes (Trockenes Holz)')
length_of_wet_wood = models.CharField(max_length=40, choices=LENGTH_OF_WET_WOOD_CHOICES, default='0.5', null=True, blank=True,verbose_name=u'Länge des Holzes')

backuped = models.BooleanField(default=False)
class Meta:
verbose_name = u'Objednávka'
verbose_name_plural = u'Objednávky'

def save(self, *args, **kwargs):
if self.type == 'retail':
self.price = Price.calculate_price(self.dry_wood, self.wet_wood, self.briquette, self.stelinka)['total']
self.price = 0

super(Order, self).save(*args, **kwargs)

def __str__(self):

return u'Objednávka {} | {} {} | {} € {} {}'.format(, self.first_name, self.last_name, self.price, u'| >>>>>>> NEPOTVRDENÁ <<<<<<<' if not self.confirmed else '',
u'| >> VYBAVENÁ <<' if self.done else '')

def __unicode__(self):
return self.__str__()


Fixtures can be used for this

To dump the data on local machine

./ dumpdata mytable > databasedump.json 

and import it on the remote :

./ loaddata databasedump.json