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 7979599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:49:05+00:00 2026-06-04T09:49:05+00:00

I would like to introduce Code First Migrations to my project, but I am

  • 0

I would like to introduce Code First Migrations to my project, but I am unsure of how to handle deploying this to my client for testing. Until now, things have been quite simple, and I have just used a CreateDatabaseIfNotExists initializer. Now, I have two scenarios:

  1. He deletes his existing, before-migrations, database, and uses an initializer to create a new, with-migrations, database, and we use migrations from here on to upgrade his database. Can I use the MigrateDatabaseToLatestVersion initializer to create the DB if missing as well?

  2. I just deploy my code and let it perform migrations. I’m not quite sure if anything but using a MigrateDatabaseToLatestVersion is required here. Will this upgrade a pre-migrations database to one suitable for migrations?

  • 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-04T09:49:06+00:00Added an answer on June 4, 2026 at 9:49 am

    This is what I do when automatic migration is required; I hope this helps you find a solution:

    Database.SetInitializer(
        new MigrateDatabaseToLatestVersion<ContextFileName, PathToMigrationsConfig>()
        );
    Database.Initialize(false);
    

    In the configuration file for the migrations, I set the following in the constructor

    AutomaticMigrationsEnabled = true;
    AutomaticMigrationDataLossAllowed = false;
    

    In the configuration file you should have an override of the seed method, if not you can add it and fill in your seed data.

    What the above will do is create/upgrade the database to the latest as long as no data loss occurs. This should allow you hand off the code to the client.


    On a side note, for a production system I will usually argue the point of not doing this. This had many disadvantages. For databases I do not have control over I have yet to find a client that has refused the generated script file.

    You can get this by using the following command after you add a migration through the Package Manager Console:

    Update-database –script -verbose
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to update session variable. Let me introduce this in simple example.
I'm fairly new to the world of versioning but would like to introduce Subversion
I would like to introduce multithreading feature in my shell script. I have a
I have a JSF application that uses mostly Richfaces. I would like to introduce
Would like to know the c# code to actually retrieve the IP type: Static
This scoping problem seems like the type of C++ quandary that Scott Meyers would
i would like to write a simple line of code, without resorting to if
Typically you will find STL code like this: for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter
I've never done code coverage in Python, but I'm looking for something like GCC
I am taking on a maintenance team and would like to introduce tools like

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.