Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:37:09+00:00 2026-06-18T05:37:09+00:00

My Seed() method is never called. It is called when I do an Update-Database

  • 0

My Seed() method is never called. It is called when I do an Update-Database from the Package Manager Console, but never when I run from code.
If I delete my database, all tables are created ( so my migration classes are executed), but my Seed() code is never called.
MVC 4, Entity Frame Work 5 Code First.

Global.asax:

protected void Application_Start()
{
  Database.SetInitializer<MyContext>(new DbInitializer());
}

DBInit:

internal class DbInitializer : MigrateDatabaseToLatestVersion<MyContext, Migrations.Configuration>
{
}

DBContext:

public partial class MyContext : DbContext
{
  public MyContext() : base("DefaultConnection")
  {
  }
  // public DBSets....
}

Configuration:

internal sealed class Configuration : DbMigrationsConfiguration<MyContext>
{
public Configuration()
{
  // The constructor is actually called
  AutomaticMigrationsEnabled = false;
}

protected override void Seed(MyContext context)
{
   // My seed code, never called
}

What could be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:37:10+00:00Added an answer on June 18, 2026 at 5:37 am

    So the reason was that I needed to specify my custom Initializer in the config file:

      <entityFramework>
          <contexts>
            <context type="EFTest2.MyContext, EFTest2">
              <databaseInitializer type="EFTest2.Initializers.DbInitializer, EFTest2" />
            </context>
          </contexts>
          <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
      </entityFramework>
    

    After that, my Seed method is called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have method which updating data in database from CSV. csv_text = File.read(#{Rails.root}/db/seed/books.csv) csv
I have a seed object which has an instance method seed:fall() which is called
I'm trying to seed my database with the standard db/seeds.rb method. This works fine
I'm trying to seed a blank database from the production db via the Import/Export
I am trying to seed users and roles into my database. Currently using Code
So I am learning MVC3 and EF4. I tried the code first method but
Can someone explain what the method seed does from module random in the following
I am trying to seed some data using custom database initializers, but can't get
So I'm planning on using the Rho::RhoUtils.load_offline_data method to seed my application's database as
I am trying to seed a database with the code first ability of EF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.