0

I have two django apps on heroku, app_B is a copy of a section of app_A.
The app_A has models with ImageField:

image = models.ImageField(null=True, upload_to=get_image_uri)

I'd like to copy these objects to the app_B.
The model I'd like to copy looks exactly the same. The images are stored in Amazon AWS.

The django command dumpdata / loaddata gives me FK errors..
However, I could try to solve those FK errors but I'm not sure if loaddata can copy the images themselves, or am I missing something?
Is there any other way to do this?

John Moutafis
  • 22,254
  • 11
  • 68
  • 112
Alejandro Veintimilla
  • 10,743
  • 23
  • 91
  • 180

1 Answers1

1

You can perform a raw SQL query:

ModelB.objects.raw(
    '''
    INSERT INTO appb_modelb (image)
    SELECT image FROM appa_modela
    '''
)

The above assumes that your tables are in the same database and your appb_modelb table is empty at the moment of the copy.

The are more complicated SQL queries that you can achieve this way, should the need rises, like copy a column to a table from a different database.

You must be careful though. Read the docs carefully and especially the warnings in there!

Good luck :)

John Moutafis
  • 22,254
  • 11
  • 68
  • 112