Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 09, 2012 04:35 PM by beetledev
Apr 09, 2012 03:37 AM|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 04:21 AM|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 04:49 AM|LINK
Nope, remove the initializer if you are going to production.
Apr 09, 2012 02:37 PM|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 04:35 PM|LINK
Thanks both, for the replies and thank you tdykstra for the additional links.