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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:03:08+00:00 2026-06-08T08:03:08+00:00

I have used MVCScaffolding from Nuget Package Manager and followed the brief tutorial on

  • 0

I have used MVCScaffolding from Nuget Package Manager and followed the brief tutorial on how it works.
It seems simple enough,and when I run
Scaffold Controller Team –Repository -Force it will create all the repository pattern stuff surrounding “Team”.

However, in an attempt(and success) to break this, I decided to add in an additional field to the “Team” class (myRandomField).
As I expected, when I compiled I got an error in the MVC View which was:

The model backing the ‘MvcApplication1Context’ context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.

Obviously this error is because I have updated the model (Code-first??) and the DB is now ‘out of sync’ with my model.

What is the best approach to get around this issue? Is there an easy way to have to DB sync with the model – I plan on doing a lot of editing to my models as the project I am starting will be rolled out gradually (So doing a complete database rebuild each time is out the question) Is code first the right approach for me in this case? I really like this plugin/tool would be a shame not to use it.

  • 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-08T08:03:10+00:00Added an answer on June 8, 2026 at 8:03 am

    jad,

    as mentioned in my comment above, if you’re ‘happy’ to lose all exisiting data in your DB, then you can add the following into your global.asax:

    [Conditional("DEBUG")]
    private static void InitializeDb()
    {
        using (var db = new YourContext())
        {
            // double indemnity to ensure just sqlserver express
            if (db.Database.Connection.DataSource != null
                && db.Database.Connection.DataSource.IndexOf("sqlexpress", 
                StringComparison.InvariantCultureIgnoreCase) > -1)
            {
                // Initializer code here
                Database.SetInitializer(new DropCreateDatabaseIfModelChanges<YourContext>());
            }
        }
    } 
    

    and then call this from Application_Start(), i.e.

    protected void Application_Start()
    {
        InitializeDb();
        ViewEngines.Engines.Add(new MobileViewEngine());
        AreaRegistration.RegisterAllAreas();
    
        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterRoutes(RouteTable.Routes);
    }
    

    if you wish to retain the data, then you’ll have to use a data migration tool. I used the Red Gate tools (SQL Comparison Bundle) to perfom this. Basically, this look at your new schema and your old schema and migrates existing data over into the new schema, ready for test and deployment, all without touching the original db file.

    I think this should work well for you.

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

Sidebar

Related Questions

I have used the code below to run cmd commands from java (code adopted
We have used Shibboleth to authenticate users. It works great. The issue is that
I have used auto complete textbox previously. That auto complete works only when i
I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I have used ajax in the code which works perfectly and give me json
I have used several looking glass tools from servers around the world. What I'm
I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/
i have used a piece of jQuery to highlight the search results, it works
I have used the jquery ajax for getting the values from the server.when the
I have used the code available from http://codeblitz.wordpress.com/2009/06/22/jquery-charts/ It uses jqPlot. So I have

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.