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

  • SEARCH
  • Home
  • 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 7974549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:24:17+00:00 2026-06-04T08:24:17+00:00

I have a system in production which was created with Entity Framework 4.1 Code

  • 0

I have a system in production which was created with Entity Framework 4.1 Code First. Now, I have upgraded to 4.3 and need to apply migrations, but there’s several use cases I need to cover:

  1. A new developer needs the database created from scratch with seed data. (The Seed() method also applies some unique indices.)
  2. The production environment needs only the unapplied changes applied. (But keep in mind that this DB was created in EF 4.1, which doesn’t have migrations.)

How do I create the migrations and an initializer (or initializers) to cover both these cases?

  • 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-04T08:24:18+00:00Added an answer on June 4, 2026 at 8:24 am

    Since your production database was created with EF 4.1, you’ll need to do a bit of work to get it ready for use with Migrations. Start with a copy of your current production code running in a dev environemnt. Make sure the dev database doesn’t exist.

    1. Upgrade the project to use EF 4.3 (or later) with Migrations and create the initial migration to snapshot what production currently looks like.

      Update-Package EntityFramework
      Enable-Migrations
      Add-Migration InitialCreate  
      
    2. Replace your database initializers with matching Migrations code.

      For seed data, add it to the Seed() method of the Migrations\Configuration.cs file. Note that unlike the Seed() method in initializers, this method gets run every time Update-Database is called. It may need to update rows (reset the seed data) instead of inserting them. The AddOrUpdate() method can aid with this.

      Since your unique indecies can now be created with Migrations, you should add them to the Up() method of the InitialCreate migration. You can either chain them off the CreateTable() calls using the Index() method, or by calling the CreateIndex() method.

      You can use the MigrateDatabaseToLatestVersion initializer now to run Migrations during initialization.

    3. Get a script to bootstrap your production environment.

      Update-Database -Script
      

      From the script that gets generated, you’ll want to delete almost everything since the tables aready exist. The parts you’ll need are the CREATE TABLE [__MigrationHistory] and INSERT INTO [__MigrationHistory] statements.

    4. Optionally, drop the EdmMetadata table since it is no longer needed.

    Once you do these things, you should be good to go with Migrations. New developers can run Update-Database to create the database from scratch, and you can run Update-Database (or use the Migrations initializer) against production to apply additional migrations there.

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

Sidebar

Related Questions

We have a production Java system which is using a lot more threads than
I have an asp.net app that uses System.IO.Path.GetTempFileName() for temporary files. In the production
I have a system which is receiving log files from different places through http
I have been debugging some existing code for which unit tests are failing on
I have a system which requires I have IDs on my data before it
I currently have a while loop, which contains an if statement: if (s.Contains(mp4:production/CATCHUP/)) Although
I currently have a system in which one rails 2.3.2 has a database with
We have system here that uses Java JNI to call a function in a
I have System.Collections.Generic.Dictionary<A, B> dict where A and B are classes, and an instance
Let's say we have system A comprising a MySQL database, with several tables. After

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.