update the database from package manager console in code first environment

c# ef-migrations entity-framework-6 sql-server visual-studio-2012


Code First Environment

I'm trying to update the database from package Manager console.If my Domain class change, I have to drop and create the database,Instead of dropping the Database how can i update the database.

I have already try by reading some blogs in google.


PM> Install-Package EntityFramework
  1. By using this command i install the Entity Framework successfully.

     PM> Enable-Migrations
  2. By using this command it created the Migration file in my project.

     PM> Update-Database
  3. By using this command , i may update the table but i have a Problem here.


Specify the '-Verbose' flag to view the SQL statements being applied to the target database. System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.

Doubt is here

Sometimes It may update if only one field changes in POCO Class. For example I have Updated the more number of Domain class ,How can i Update the Database from Package manager Console. Any Idea ?

1/11/2016 1:28:48 PM

Accepted Answer

You can specify connection string via ConnectionString parameter:

Update-Database -ConnectionString "data source=server_name;initial catalog=db_name;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" -ConnectionProviderName "System.Data.SqlClient" -Verbose

Also you need to use this parameter with the same value for Add-Migration command:

Add-Migration Version_Name -ConnectionString "data source=server_name;initial catalog=db_name;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" -ConnectionProviderName "System.Data.SqlClient" -Verbose
8/25/2015 5:15:00 AM

Popular Answer

I used

Enable-Migrations -EnableAutomaticMigrations -Force



And this migrated my changes (additional columns) while preserving my test data. I think this is the laziest option while prototyping.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow