User1520731567 posted
Hi skyblue28,
My question is how do I now get this to migrate and update the localdb table with new fields. When i do add-migration it comes up blank with no changes.
Also my next question is currently I am using test sql db in development. When this launches to a new sql server, I want it to create a database and the associated models as tables?
If it comes up blank with no changes, it seems that there's no change for db or model.
I suggest you could follow the steps to implement code first migration.
1.Add the latest version of the EntityFramework NuGet package to the project
Tools –> Library Package Manager –> Package Manager Console
Run the Install-Package EntityFramework command
2.Create the Model
3.Create a Context
4.Statement this model in the Context,like:
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.Infrastructure;
namespace MigrationsDemo
{
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
}
public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }
}
}
5.Run the Enable-Migrations command in Package Manager Console
6.Run the Add-Migration XXXX command in Package Manager Console,It will generate a migration file which filename with timestamp.
7.Run the Update-Database command in Package Manager Console,it will generate a database.
If you have any changes, you need to run Add-Migration XXXX and Update-Database in the Console.
More details, you could refer to these links:
https://msdn.microsoft.com/en-us/library/jj591621(v=vs.113).aspx
https://msdn.microsoft.com/en-us/library/jj193542(v=vs.113).aspx#Summary
Best Regards.
Yuki Tao