seed

how to seed in Yii?

醉酒当歌 提交于 2019-12-22 09:06:48
问题 I'm wondering how one can seed in Yii a table once it is created with migration? I've got a migration with an up-method: public function up() { $this->createTable('users',array('id'=>"pk", 'login'=>'string NOT NULL')); echo "table 'users' is created.\n"; return true; } I've got as well corresponding Users model and its CRUD actions . When I try to execute another migration with an up-method public function up() { $user = new Users; $user->login = "Bob"; return $user->save(); } I get the

boost::random generate the same number every time

巧了我就是萌 提交于 2019-12-19 05:33:50
问题 main .cpp #include "stdafx.h" #include "random_generator.h" int main ( int argc, char *argv[] ) { cout.setf(ios::fixed); base_generator_type base_generator; int max = pow(10, 2); distribution_type dist(1, max); boost::variate_generator<base_generator_type&, distribution_type > uni(base_generator, dist); for ( int i=0; i<10; i++ ) { //cout << random_number(2) << endl; cout << uni() << endl; } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */ random_gemerator.h #include

How to use Seed data with Paperclip + S3

非 Y 不嫁゛ 提交于 2019-12-18 16:19:17
问题 I'm trying to seed my database with member profiles and also member profile pictures with S3 and paperclip but it doesn't seem to be working. I can create/edit existing members within the application to add pictures with paperclip + S3 and it works just fine but seeding it doesn't work. I have searched but can't find an answer. 回答1: I don't know what is your exact problem but you can try something like this in your seeds.rb file : u = User.new({:name => 'username', :email => 'user@name.fr'...

What is the function of the seeds.rb file?

假如想象 提交于 2019-12-18 13:27:18
问题 I am very new to Ruby on Rails. I don't know what the function of the seed.rb file is, why we use this file, and why we need to run the rake db:seed command. Can anyone give an explanation with examples? 回答1: Bootstrapping Data The purpose of seed data is to bootstrap your database. For example, if you have a users table where you track users' city and state, you may want to seed a related table with U.S. state names and abbreviations before creating the first user. Likewise, you may also

Undo previously seeded data in Rails

为君一笑 提交于 2019-12-18 04:47:04
问题 I have seeded a row of data to my table by editing db/seed.rb file and executing rake db:seed command. Unknowingly, I put some wrong information in to that row. So I want to remove the previously added row of data. Is there any rake command for the same like rake db:rollback for rake db:migrate . 回答1: There are a couple of aspects to this: 1: You want to change the seed data when no other data is present in the database: You should simply redo the rake db:seed after updating the seed.rb file.

Seeding users with Devise in Ruby on Rails

守給你的承諾、 提交于 2019-12-17 23:10:16
问题 In my development and test environments, I want to seed the database with a bunch of users. I'm using Ruby on Rails v3.2.8 and the latest Devise. So I added this line in my db/seeds.rb file: User.create(email: 'test@example.com', encrypted_password: '#$taawktljasktlw4aaglj') However, when I run rake db:setup , I get the following error: rake aborted! Can't mass-assign protected attributes: encrypted_password What is the proper way to seed users? 回答1: You have to do like this: user = User.new

How to seed data with AddOrUpdate with a complex key in EF 4.3

点点圈 提交于 2019-12-17 21:42:21
问题 I am trying to seed a development database with some test data. I have used context.People.AddOrUpdate(p => p.Id, people)); with much success. I have another table that I need to seed, in which I would not know the primary key. For example, I would want to AddOrUpdate based on the First and Last names matching. I am unsure how to write the Expression correctly. context.People.AddOrUpdate(p => p.FirstName && p.LastName, people); is obviously incorrect, but I hope it conveys the solution I am

Random seed at runtime

时光总嘲笑我的痴心妄想 提交于 2019-12-17 20:15:33
问题 How can I generate different random numbers at runtime? I've tried srand((unsigned) time(0)); But it seems to get me a random number on every startup of the program, but not on every execution of the function itself... I'm trying to automate some tests with random numbers, random iterations, number of elements, etc... I thought I could just call srand((unsigned) time(0)); at the beginning of my test function and bingo, but apparently not. What would you suggest me to do? 回答1: srand() As

set random seed programwide in python

匆匆过客 提交于 2019-12-17 15:53:38
问题 I have a rather big program, where I use functions from the random module in different files. I would like to be able to set the random seed once, at one place, to make the program always return the same results. Can that even be achieved in python ? 回答1: The main python module that is run should import random and call random.seed(n) - this is shared between all other imports of random as long as somewhere else doesn't reset the seed. 回答2: zss's comment should be highlighted as an actual

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

断了今生、忘了曾经 提交于 2019-12-17 15:39:35
问题 Is there any way to find out what seed Python used to seed its random number generator? I know I can specify my own seed, but I'm quite happy with Python managing it. But, I do want to know what seed it used, so that if I like the results I'm getting in a particular run, I could reproduce that run later. If I had the seed that was used then I could. If the answer is I can't, then what's the best way to generate a seed myself? I want them to always be different from run to run---I just want to