Posted on

django seeds

Django seeds

Should you need, you can also specify what value a particular field should have. For example, if you want to seed 15 of MyModel , but you need my_field to be the same on all of them, you can do it like this:

Using with command

That’s it! Now you have 15 of each model seeded into your database.

With django-seed, you can seed your database with test data from the command line using the seed command.

Note: When seeding models with Foreign Keys, you need to make sure that those models are seeded first. For example, if a model in app A has a foreign key to a model in app B, you must seed app B first.

Django-seed allows you to write code to generate models, and seed your database with one simple command!

Ex: seeding 5 Game and 10 Player objects:

Using with code

Main reason I want to seed some data on statuses, types, etc for the project initialization.

Is there something similar ?

I’ved been developing in Django and was wondering if there is a way to seed data into the database in Django.

5 Answers 5

In ruby on rails, I use seed.rb and then run “rake db:seed” in command line.

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