seeding
Laravel 5.1 refresh and seed a single table
You could use migrate:refresh command that will roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database : php artisan migrate:refresh And you may use the –class option to specify a specific seeder class to run individually : php artisan db:seed –class=UserTableSeeder The full code will … Read more
RoR, Can’t iterate from DateTime/TimeWithZone
start = someModel.start_date.to_datetime finish = someModel.end_date.to_datetime while(start < finish) do #bunch of awesome stuff start += 1.day end
Can I pass an argument to rake db:seed?
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 minimal=yes and unless ENV[“minimal”] # do stuff etc
FactoryGirl + Faker – same data being generated for every object in db seed data
You need to pass a block if you want the values re-evaluated for each instance created. Instead of email Faker::Internet.email try… email { Faker::Internet.email }
Entity Framework – Migrations – Code First – Seeding per Migration
When I have fixed data that I want to insert with a migration, I put the inserts directly in the Up() migration using calls to Sql(“Insert …”). See the note halfway down this page: how to insert fixed data You prevent duplicates in the Seed method by calling the AddOrUpdate overload that takes an identifier … Read more
How to Seed Users and Roles with Code First Migration using Identity ASP.NET Core
My way of doing this is to create a class in models namespace. public class SampleData { public static void Initialize(IServiceProvider serviceProvider) { var context = serviceProvider.GetService<ApplicationDbContext>(); string[] roles = new string[] { “Owner”, “Administrator”, “Manager”, “Editor”, “Buyer”, “Business”, “Seller”, “Subscriber” }; foreach (string role in roles) { var roleStore = new RoleStore<IdentityRole>(context); if (!context.Roles.Any(r … Read more
Rails: Invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed
You’re receiving an encoding error because your filesystem isn’t configured to encode the date you’ve added (since presumably it includes new characters – possibly in your HTML entity encoded map URL – that didn’t exist in your prior data seed). The following will should resolve this error by setting the UTF-8 locale on your machine: … Read more
MVC 5 Seed Users and Roles
Here is example of usual Seed approach: protected override void Seed(SecurityModule.DataContexts.IdentityDb context) { if (!context.Roles.Any(r => r.Name == “AppAdmin”)) { var store = new RoleStore<IdentityRole>(context); var manager = new RoleManager<IdentityRole>(store); var role = new IdentityRole { Name = “AppAdmin” }; manager.Create(role); } if (!context.Users.Any(u => u.UserName == “founder”)) { var store = new UserStore<ApplicationUser>(context); var … Read more
EntityType ‘IdentityUserLogin’ has no key defined. Define the key for this EntityType
In my case I had inherited from the IdentityDbContext correctly (with my own custom types and key defined) but had inadvertantly removed the call to the base class’s OnModelCreating: protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // I had removed this /// Rest of on model creating here. } Which then fixed up my missing … Read more