I'ved been developing in Django and was wondering if there is a way to seed data into the database in Django.
In ruby on rails, I use seed.rb and then run "rake db:seed" in command line.
Main reason I want to seed some data on statuses, types, etc for the project initialization.
Is there something similar ?
Best Answer
Similar to Rails, we also have option to seed the database. It is done using management commands. In one of your apps, use the following folder structure
this makes
python manage.py seed
available as a management command. I personally follow the following structure.In above structure you could, add custom modes, and seed accordingly. Also you could add additional management command arguments (e.g. number_of_addresses and pass it to run seed. the command would be
python manage.py seed --mode=refresh --number_of_addresses=15
).Hope this helps. Cheers!