seeding

Sequelize dynamic seeding

随声附和 提交于 2019-12-06 05:14:53
问题 I'm currently seeding data with Sequelize.js and using hard coded values for association IDs. This is not ideal because I really should be able to do this dynamically right? For example, associating users and profiles with a "has one" and "belongs to" association. I don't necessarily want to seed users with a hard coded profileId . I'd rather do that in the profiles seeds after I create profiles. Adding the profileId to a user dynamically once profiles have been created. Is this possible and

Laravel Seeding Does not Fill in Fields

流过昼夜 提交于 2019-12-06 03:04:55
问题 I have a database seed file: class ContactTableSeeder extends Seeder { public function run() { $contacts = array( array( 'first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'test.contact@emai.com', 'telephone_number' => '0111345685', 'address' => 'Address', 'city' => 'City', 'postcode' => 'postcode', 'position' => 'Director', 'account_id' => 1 ) ); foreach ($contacts as $contact) { Contact::create($contact); } } } When I run php artisan migrate:refresh --seed it seeds the database

How to create a new record for a many-to-many through association that accepts nested attributes?

让人想犯罪 __ 提交于 2019-12-06 01:17:35
Organization and User have a many-to-many association through Relationship . Initially I implemented this a 1-to-many association, which worked but now I need it to become a many-to-many through association. So I created the Relationship model and changed the association in the model files. Organization accepts nested attributes for User as in my app I have a joined signup form for the two. Also, I use it in my seeds file: Organization.create!(name: "name", ...).users.create(email: "email@email.com", ...) This worked when it was a 1-to-many association but now it is a many-to-many through

Laravel 5 Reseeding the Database for Unit Testing Between Tests

蓝咒 提交于 2019-12-05 08:10:45
I start with a seeded database and am trying to reseed the database between unit tests in Laravel 5. In Laravel 4 I understand you could simply use Illuminate\Support\Facades\Artisan and run the commands Artisan::call('migrate'); Artisan::call('db:seed'); or you supposedly could do: $this->seed('DatabaseSeeder'); before every test. In Laravel 5 this appears to have been replaced by use DatabaseMigrations; or use DatabaseTransactions; I have tried using these and have managed to get the tests to migrate the database; however, it doesn't actually reseed the data in the tables. I have read

RoR, Can't iterate from DateTime/TimeWithZone

笑着哭i 提交于 2019-12-04 15:26:07
问题 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

Sequelize dynamic seeding

纵然是瞬间 提交于 2019-12-04 11:35:31
I'm currently seeding data with Sequelize.js and using hard coded values for association IDs. This is not ideal because I really should be able to do this dynamically right? For example, associating users and profiles with a "has one" and "belongs to" association. I don't necessarily want to seed users with a hard coded profileId . I'd rather do that in the profiles seeds after I create profiles. Adding the profileId to a user dynamically once profiles have been created. Is this possible and the normal convention when working with Sequelize.js? Or is it more common to just hard code

Seeding database with path from code?

霸气de小男生 提交于 2019-12-04 11:20:28
I've been using Laravel's migrations with the path parameter like so: Artisan::call('migrate', array('--path' => 'path/to/my/Migrations')); Is there anyway I can run the seed command in the same way? I have a number of seed files I want to use but I don't want to run them all at the same time. Any advice appreciated. Thanks Instead of --path you can set --class with namespace to Seeder class. Artisan::call('db:seed', [ '--class' => 'Namespace\Seeds\DatabaseSeeder' ]); This work on Laravel 5.1 Seeding only Artisan::call('db:seed'); Re-run all migration under specified path & run seeds as well

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

允我心安 提交于 2019-12-04 07:20:04
问题 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? 回答1: 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 回答2: 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

Laravel Seeding Does not Fill in Fields

江枫思渺然 提交于 2019-12-04 06:49:29
I have a database seed file: class ContactTableSeeder extends Seeder { public function run() { $contacts = array( array( 'first_name' => 'Test', 'last_name' => 'Contact', 'email' => 'test.contact@emai.com', 'telephone_number' => '0111345685', 'address' => 'Address', 'city' => 'City', 'postcode' => 'postcode', 'position' => 'Director', 'account_id' => 1 ) ); foreach ($contacts as $contact) { Contact::create($contact); } } } When I run php artisan migrate:refresh --seed it seeds the database and creates the relevant record in the contacts table, except that it does not fill the fields with any

Entity Framework - Seed AddOrUpdate with multi column index as identifier

拈花ヽ惹草 提交于 2019-12-04 03:04:32
I am trying to seed a database using the context.AddOrUpdate method, but the problem is that I need to make the inserted data unique based on a multi column index. [Table("climbing_grades")] public class ClimbingGrade : EntityBase { /// <summary> /// The name of the climbing grade, e.g.: 7a, VII, etc. /// </summary> [Index("IX_Name_GradeType", 1, IsUnique = true)] public string Name { get; set; } /// <summary> /// Tries to display the average difficulty of the described grade. /// Matching the different grades can be difficult because its always /// a subjective rating and there exists no norm