export data from Django database
Asked Answered
I

1

6

how to copy records from one database to another django ?

I tried for the first database

python manage.py dumpdata material - indent = 1

material is the directory database after ?

material.json ?

do I copy this file somewhere? in the second database ?

Inanity answered 18/9, 2013 at 6:33 Comment(0)
F
12

You can use this command to dump the data to a json file:

python manage.py dumpdata material --indent=1 > my_dir/material.json

And then this command to load it into the database:

python manage.py loaddata my_dir/material.json
Foin answered 18/9, 2013 at 6:37 Comment(17)
when I write python manage.py dumpdata material - indent = 1 material.json I created the file? if i go the second directory (env) C: \ 01_07 \ myproject> python manage.py loaddata 03_07bis/monprojet/material.json I get Installed 0 object (s) from 0 fixture (s)Inanity
Are the database tables the same as the tables on the server you dumped fromFoin
yes all files are identical. It's two databases with two different names only records are differentInanity
Have you checked that the file contains valid json entries.Foin
which file ? material.json ?Inanity
which file ? material.json ?Inanity
Yes and check that the model points to the correct app and model.Foin
I have seven materials in the first databaseInanity
when i write python manage.py dumpdata material --indent=1 i point on the datas of the first material normaly I would find in the file the names of the seven materials I get this when I execute python...pastebin.com/V9ajirHMInanity
all other classes of my model are missing in the file !Inanity
I do not fully understand your second to last commentFoin
I must be in the file material.json all fields defined in the model I have fields related to a single class here is an example of what I should have : pastebin.com/8EP11RsCInanity
If you dump the data to file and then use the 'loaddata' command to load the json file, what error do you get? this should go smoothly id the databases and app structure is identical.Foin
(env) C:\01_07\monprojet>python manage.py loaddata 03_07bis/monprojet/material.json I get Installed 0 object(s) from 0 fixture(s) because the file is like pastebin.com/V9ajirHM and not like pastebin.com/8EP11RsCInanity
I tried this : (env) C:\03_07bis\monprojet>python manage.py dumpdata material.Category material .Material material.Property material.Physic material.Physic2 material.Physic3 ma terial.Physic4 material.Physic5 material.Physic6 material.UniteProperty2 materia l.Essai_Temperature material.Media2 --indent=1 but I get the sameInanity
Yes and how are you attempting to load it back into the databaseFoin
If the model path is correct and the data in the fixture is also correct I also can not see why this would not work.Foin

© 2022 - 2024 — McMap. All rights reserved.