seeding

RoR, Can't iterate from DateTime/TimeWithZone

点点圈 提交于 2019-12-03 09:32:59
I have a simple task where I want to take a starting date and an ending date and loop over the days/dates. This code is being used in my db:seed rake task. Currently, my code has gone through the following attempts. (someModel.start_date.to_datetime..someModel.end_date.to_datetime).each { |x| puts x } ...... (someModel.start_date...someModel.end_date).each { |x| puts x } In each case, I get an error like this. can't iterate from ActiveSupport::TimeWithZone or can't iterate from DateTime If anyone has any clue on how to iterate over a range of DateTimes I'd be greatly appreciative. start =

FactoryGirl + Faker - same data being generated for every object in db seed data

孤者浪人 提交于 2019-12-03 08:10:45
问题 I am using FactoryGirl and Faker to generate user objects in my seeds.rb file but for some reason the exact same user is being created and rake db:seed is failing because of an email uniqueness validation. Factory for users: #users.rb require 'faker' FactoryGirl.define do factory :user do first_name Faker::Name.first_name last_name Faker::Name.last_name phone Faker::PhoneNumber.cell_phone email Faker::Internet.email password "password" password_confirmation "password" end end And the code in

Laravel 5.3 db:seed command simply doesn't work

余生长醉 提交于 2019-12-03 04:55:42
I do everything by-the-book: Installed fresh Laravel 5.3.9 app (all my non-fresh apps produce the same error) run php artisan make:auth create migrations for a new table `php artisan make:migration create_quotations_table --create=quotations Schema::create('quotations', function (Blueprint $table) { $table->increments('id'); $table->string('text'); // my problem persists even with the below two columns commented out $table->integer('creator_id')->unsigned()->index('creator_id'); $table->integer('updater_id')->unsigned()->index('updater_id'); $table->softDeletes(); $table->timestamps(); });

Can I pass an argument to rake db:seed?

杀马特。学长 韩版系。学妹 提交于 2019-12-03 04:46:31
问题 Part of my seeds.rb loads a lot of data into the database. I want to be able to selectively load this data. E.g. $ rake db:seed or $rake db:seed[0] would just load the necessary data to run the site, while $ rake db:seed[1] would load my big data file into the database as well. Is this possible? How can I make this happen? If not, can anyone think of a way to do what I'm trying to do? 回答1: Rake arguments are painful to pass around, unfortunately (and db:seed doesn't pass its arguments through

FactoryGirl + Faker - same data being generated for every object in db seed data

99封情书 提交于 2019-12-02 21:43:52
I am using FactoryGirl and Faker to generate user objects in my seeds.rb file but for some reason the exact same user is being created and rake db:seed is failing because of an email uniqueness validation. Factory for users: #users.rb require 'faker' FactoryGirl.define do factory :user do first_name Faker::Name.first_name last_name Faker::Name.last_name phone Faker::PhoneNumber.cell_phone email Faker::Internet.email password "password" password_confirmation "password" end end And the code in seeds.rb file: #seeds.rb rand(5..11).times { FactoryGirl.create(:user) } Error: ActiveRecord:

Can I pass an argument to rake db:seed?

青春壹個敷衍的年華 提交于 2019-12-02 17:59:59
Part of my seeds.rb loads a lot of data into the database. I want to be able to selectively load this data. E.g. $ rake db:seed or $rake db:seed[0] would just load the necessary data to run the site, while $ rake db:seed[1] would load my big data file into the database as well. Is this possible? How can I make this happen? If not, can anyone think of a way to do what I'm trying to do? Rake arguments are painful to pass around, unfortunately (and db:seed doesn't pass its arguments through, regardless). Your best bet is to use environment variables to pass your extra args through: rake db:seed

Entity Framework inserting duplicates on Seeding database [duplicate]

我只是一个虾纸丫 提交于 2019-12-02 14:56:33
问题 This question already has an answer here : Entity Framework database mapping relationships (Duplicate creation using Seed() method) (1 answer) Closed 12 months ago . EDIT---- From here i tried assigning Id's in the seeding method and this was OK for Languages but not when i added Address to the customer and assign Id's as well to these addresses, than it created the dupes again... Both Address & Language are declared as DbSet<...> in my Context What i tried: Adding 1 Address (with Id) - add

Reset the database (purge all), then seed a database

眉间皱痕 提交于 2019-12-02 13:49:48
Is there a rake command to wipe out the data in the database tables? How do I create a db:seed script to pre-fill data to my tables? I use rake db:reset which drops and then recreates the database and includes your seeds.rb file. http://guides.rubyonrails.org/migrations.html#resetting-the-database You can delete everything and recreate database + seeds with both: rake db:reset : loads from schema.rb rake db:drop db:create db:migrate db:seed : loads from migrations Make sure you have no connections to db (rails server, sql client..) or the db won't drop. schema.rb is a snapshot of the current

Seeding method is inserting additional Entities with NULL values

时光怂恿深爱的人放手 提交于 2019-12-02 10:19:32
I am having this strange behavior all of a sudden (i have compared my files in version control (tfs) to be sure i did not change anything and i didn't found anything different). I am seeding my database with some metadata and i see that it has a very strange behavior i never saw before. I am inserting a Entity "Product" and it inserts this entity 2 times , first insert is correct and has everything it should have, the other one has NULL properties (string values) but some (like datetimes) have values. I have totally no clue why this is happening, it is occurring when i call the base.Seed(ctx);

Entity Framework inserting duplicates on Seeding database [duplicate]

こ雲淡風輕ζ 提交于 2019-12-02 08:31:48
This question is an exact duplicate of: Entity Framework database mapping relationships (Duplicate creation using Seed() method) 1 answer EDIT---- From here i tried assigning Id's in the seeding method and this was OK for Languages but not when i added Address to the customer and assign Id's as well to these addresses, than it created the dupes again... Both Address & Language are declared as DbSet<...> in my Context What i tried: Adding 1 Address (with Id) - add this to 1 customer => Creates a dupe Adding 1 language & 1 Address (with Id's) - add both to 1 customer => Creates a dupe Adding 1