Last post Apr 09, 2012 05:35 PM by beetledev
Apr 09, 2012 04:37 AM|beetledev|LINK
I am using EF Code First in an MVC project. I am wondering if it is possible to configure it so that it will create the database and seed the tables only if the database does not exisit.
Right now I have it with DropCreateDatabaseIfModelChanges but I don't want to drop or seed the database ever, unless it doesn't exist.
Apr 09, 2012 05:21 AM|beetledev|LINK
I found this: CreateDatabaseIfNotExists
From what I read that is the default that EF Code First uses. I guess my question is now, is it safe to set my initializer to this and go to production without any other changes?
I also found that it's possible to set the initializer in the web.config instead of the global.asax and when going to production I can just remove the initialization app config setting so that EF Code First doesn't do the initialization.
Is there anything else to be aware of?
Apr 09, 2012 05:49 AM|jsiahaan|LINK
Nope, remove the initializer if you are going to production.
Apr 09, 2012 03:37 PM|tdykstra|LINK
You don't have to change the code when you go to production, you can just change a Web.config setting -- see Preventing Entity Framework Code First from Dropping the Production Database in this tutorial:
You should also consider using Migrations in the latest release of Entity Framework (4.3.1), which will facilitate database changes after you're in production. See
Apr 09, 2012 05:35 PM|beetledev|LINK
Thanks both, for the replies and thank you tdykstra for the additional links.