How to seed Django project ? – insert a bunch of data into the project for initialization

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 <project>/<app>/management/commands/seed.py this makes python manage.py seed available as a management command. I personally follow the following structure. # <project>/<app>/management/commands/seed.py from django.core.management.base import BaseCommand import random # python manage.py … Read more

Java random numbers using a seed

If you’re giving the same seed, that’s normal. That’s an important feature allowing tests. Check this to understand pseudo random generation and seeds: Pseudorandom number generator A pseudorandom number generator (PRNG), also known as a deterministic random bit generator DRBG, is an algorithm for generating a sequence of numbers that approximates the properties of random … Read more

Seed multiple rows at once laravel 5

If you have to use the model you need a loop: foreach($users as $user){ User::create($user); } Otherwise you can just use DB::table() and insert: DB::table(‘users’)->insert($users); Actually you can also call insert() on the model (the resulting query is the same) User::insert($users); Note if you choose the insert method you loose special Eloquent functionality such as … Read more

how to query seed used by random.random()?

It is not possible to get the automatic seed back out from the generator. I normally generate seeds like this: seed = random.randrange(sys.maxsize) rng = random.Random(seed) print(“Seed was:”, seed) This way it is time-based, so each time you run the script (manually) it will be different, but if you are using multiple generators they won’t … Read more

How to re-seed a table identity in SQL Server 2008 and undo it all safely?

The command to reset the identity property is DBCC CHECKIDENT (tablename, RESEED, new_reseed_value) When you want to set the column identity to 12345 you run this DBCC CHECKIDENT (beer, RESEED, 12345) When you want to delete test rows and restore the value to the previous value, you do the following. DELETE FROM beer WHERE beer_id … Read more

Adding a custom seed file

Start by creating a separate directory to hold your custom seeds – this example uses db/seeds. Then, create a custom task by adding a rakefile to your lib/tasks directory: # lib/tasks/custom_seed.rake namespace :db do namespace :seed do Dir[Rails.root.join(‘db’, ‘seeds’, ‘*.rb’)].each do |filename| task_name = File.basename(filename, ‘.rb’) desc “Seed ” + task_name + “, based on … Read more

What is the best way to seed a database in Rails?

Updating since these answers are slightly outdated (although some still apply). Simple feature added in rails 2.3.4, db/seeds.rb Provides a new rake task rake db:seed Good for populating common static records like states, countries, etc… http://railscasts.com/episodes/179-seed-data *Note that you can use fixtures if you had already created them to also populate with the db:seed task … Read more