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 ?

user1788104
  • 81
  • 1
  • 5

1 Answers1

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
CJ4
  • 2,485
  • 3
  • 26
  • 29
  • 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) – user1788104 Sep 18 '13 at 07:26
  • Are the database tables the same as the tables on the server you dumped from – CJ4 Sep 18 '13 at 07:54
  • yes all files are identical. It's two databases with two different names only records are different – user1788104 Sep 18 '13 at 08:13
  • Have you checked that the file contains valid json entries. – CJ4 Sep 18 '13 at 08:57
  • which file ? material.json ? – user1788104 Sep 18 '13 at 13:07
  • which file ? material.json ? – user1788104 Sep 18 '13 at 13:08
  • Yes and check that the model points to the correct app and model. – CJ4 Sep 18 '13 at 14:13
  • I have seven materials in the first database – user1788104 Sep 18 '13 at 15:32
  • 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...http://pastebin.com/V9ajirHM – user1788104 Sep 18 '13 at 15:43
  • all other classes of my model are missing in the file ! – user1788104 Sep 18 '13 at 15:52
  • I do not fully understand your second to last comment – CJ4 Sep 18 '13 at 16:10
  • 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 : http://pastebin.com/8EP11RsC – user1788104 Sep 19 '13 at 05:56
  • 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. – CJ4 Sep 19 '13 at 07:05
  • (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/8EP11RsC – user1788104 Sep 19 '13 at 07:47
  • 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 same – user1788104 Sep 19 '13 at 08:21
  • Yes and how are you attempting to load it back into the database – CJ4 Sep 19 '13 at 08:48
  • 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. – CJ4 Sep 19 '13 at 10:10