Reputation: 11523
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?
Upvotes: 0
Views: 58
Reputation: 23134
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 :)
Upvotes: 1