1

I have a database with several tables in AZURE SQL Server.

I want to add a new column to one of the tables, but I want to keep all the content of the tables including the table with the new column; hence I don't want to use the

Database.SetInitializer<MyDbContext>(new DropCreateDatabaseIfModelChanges<MyDbContext>());

My code looks like this:

public class DBTables : DbContext
{
    public DBTables() : base(ProductKeys.GetDbKey()) 
    {
    }

    public DbSet<ElementsForPointTable> ElementsForPointTable { get; set; }
    public DbSet<StationsDetailsTable> StationsDetailsTable { get; set; }
}

How do I do it?

1
  • What's the issue with normal Add-Migration and Update-Database through package console? Commented Aug 19, 2017 at 12:50

1 Answer 1

1

You could use migrations to update the database scheme.

  1. Open Package Manager Console (Tools -> Library Package Manager -> Package Manager Console)
  2. Run Enable-Migrations command
  3. Change your model
  4. Run Add-Migration command in Package Manager Console.
  5. Run Update-Database command to apply your model changes to the database.
Sign up to request clarification or add additional context in comments.

3 Comments

But i am connecting the db name dynamically so how does the migration tools knows to what db to migrate to ? I have attached my code sample above
By your connection string in your Web.config
Suppose bullet number 2 should be Enable-Migrations (with an s)

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.