While developing an application I used EF automatic migrations. So now when I have deployed my app on VPS, I don't know how to add new tables and fields to my database.
Can I connect to the remote database directly from my project in VS2012, updating a connection string, and update the database using "update-database" in package manager console? Or do I need to install VS on my VPS and update the database from VPS?
My database is already filled with data, so I can't delete it and create again.
Right-click anywhere on the design surface, and select Update Model from Database. In the Update Wizard, select the Refresh tab and then select Tables > dbo > Student. Click Finish.
There is no way to convert your code-first classes into database-first classes. Creating the model from the database will create a whole new set of classes, regardless of the presence of your code-first classes. However, you might not want to delete your code-first classes right away.
After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.
Yes you can use Visual Studio, follow this tutorial - it should work for VS 2012 too.
You can also use Code first Migration to update your model by using this command in package manager console:
Update-Database
and you can specify your connection string name:
Update-Database -ConnectionStringName "MyConnectionString"
This is best explained in the link below. Read the "Getting a SQL script" section. That will explain how to generate a script which you can then run on your target database.
This will be necessary if your database access is IP protected for example.
https://msdn.microsoft.com/en-us/data/jj591621.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With