2

In a new development project using Entity Framework 6.0 code-first I had to update my models quite a bit. The update script that was automatically generated using Add-Migration in Package Manager Console got quite complex so I decided to start over. To do this I deleted the database from localhost and deleted the Migrations folder in the project. However when I re-ran the Add-Migration-command I got the following message and the same update-script was generated again:

The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration.

I was fairly certain this was because __MigrationHistory-table was still there somehow. I went into the database again but nothing had been created and the database was still gone.

Connection string used in web.config:

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=localhost;Initial Catalog=WebApp;Integrated Security=sspi;Pooling=false;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

I then checked my processes and saw two versions of the sqlservr.exe-process and LocalDb came to mind. I connected to (LocalDb)\MSSQLLocalDB and there was a new database named 'DefaultConnection' with all tables for the project. When I deleted this database I got a fresh script from the Add-Migration-command. Somewhere along the line a switch must have been made since I'm 100% certain I have been working against the SQL Server Express host at some time (All tables prior to the update script where there when I deleted the database) and for all my other project localhost works with Data Source=localhost. I can't understand why the database name is DefaultConnection instead of WebApp either. Connecting to localhost, the database name was WebApp. Has anyone experienced this before?

enter image description here

1 Answer 1

9

Finally found an answer to it. In Package Manager Console it is not enough to set Default project to the project containing DbContext you ALSO need to make sure that your website is set as the Default StartUp Project!

This small change made everything work normal again.

I cannot find this documented anywhere so I hope it will help someone.

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

1 Comment

regardless of my CS. It is using localDb and not a sql server developer edition. It also names the database after my connection name and namespace. I called it DEEBEE and it created DAL.DEEBEE. I'm still stuck.

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.