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'. 
3
  • Just leave the Initializer as it is, and delete the database manually. To apply the next changes use the EF Code-First Migrations. Commented Jul 21, 2014 at 8:51
  • Can you have a look at my edit? Commented Jul 21, 2014 at 9: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. Commented Jul 21, 2014 at 9:43

1 Answer 1

0

Try to use DropCreateDatabaseAlways class. Similar quetion here.

Be carefull, it always drops and recreates your database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.