Usually I make projects with database first, now I tried (due to the ASP.NET login framework) the code first approach. So far so good, all works. Now I needed to add a new model to the project, did this and added the model in the DbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<Order> Orders { get; set; } // existing one
public System.Data.Entity.DbSet<Document> Documents { get; set; } // new one
}
So I already have data in the orders table in my database and users in the asp.net user tables, I can't allow to drop the db, so I thought, automatic migration:
Package Manager > Enable-Migrations -EnableAutomaticMigrations
And then
PM > update-database (-f)
however, this returns:
No pending explicit migrations.
The table just won't be created. However, a new folder called Migrations was created with 2 files: ###########_dbname.cs and Configurations.cs
Any hints why my table won't be created? I even tried this in the migration file
public partial class project: DbMigration
{
public override void Up()
{
CreateTable("dbo.Documents", c => new
{
DocumentId = c.Int(nullable: false, identity: true),
Label = c.Int(nullable: false),
Data = c.Binary(),
OrderId = c.Int(nullable: false)
}).PrimaryKey(t => t.DocumentId)
.ForeignKey("dbo.Orders", t => t.OrderId, cascadeDelete: true);
in vain
UPDATE
If I perform add-migration, the following file is being created, how do I modify it?
using System;
using System.Data.Entity.Migrations;
public partial class documents : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
simply performing update-database doesn't change anything