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

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 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

How to load db:seed data into test database automatically?

The db:seed rake task primarily just loads the db/seeds.rb script. Therefore just execute that file to load the data. load “#{Rails.root}/db/seeds.rb” # or Rails.application.load_seed Where to place that depends on what testing framework you are using and whether you want it to be loaded before every test or just once at the beginning. You could … Read more