0

I am coding a C# MVC 5 internet application and I have changed the context class. I wish to create a new database with the changed context class as I am getting the following error:

Invalid object name 'dbo.MapLocations'.

I have renamed the database name in the web.config, compiled and run the application, yet am still getting the above error.

How can I recreate the database to have the structure of my context class such that I do not get the above error? I thought that specifying a new database name will automatically create a new database using the entity framework.

I have no important data in the database.

Thanks in advance

EDIT

I have manually deleted the files in the App_Data folder for the project, enabled migrations, added a migration and then updated the database.

This is the error that I am getting in the package manager console:

Cannot attach the file 'C:\Users\**path**\App_Data\CanFindLocation.Context.DataContext.mdf' as database 'CanFindLocation.Context.DataContext'. 
Simon
  • 7,991
  • 21
  • 83
  • 163
  • Just leave the Initializer as it is, and delete the database manually. To apply the next changes use the [EF Code-First Migrations](http://msdn.microsoft.com/en-us/data/jj591621.aspx). – Lukas G Jul 21 '14 at 08:51
  • Can you have a look at my edit? – Simon Jul 21 '14 at 09:13
  • You should not use Solution Explorer to delete the DB manually. Use SQL Server Object Explorer instead, then delete the Migrations folder (this time from Solution Explorer), finally, from the PM-Console, enable the migrations again, run `Add-Migration` for the `InitialCreate` and run the `Update-Database` command. – Lukas G Jul 21 '14 at 09:43

1 Answers1

0

Try to use DropCreateDatabaseAlways class. Similar quetion here.

Be carefull, it always drops and recreates your database.

Community
  • 1
  • 1
Martin Volek
  • 1,079
  • 3
  • 12
  • 27