ASP.Net MVC Guide

Enable Migrations

At the Package Manager Console:

PM> enable-migrations
More than one context type was found in the assembly 'BookBuyersGuideMVC'.
To enable migrations for BookBuyersGuideMVC.DAL.GuideContext, use Enable-Migrations -ContextTypeName BookBuyersGuideMVC.DAL.GuideContext.
To enable migrations for BookBuyersGuideMVC.Models.UsersContext, use Enable-Migrations -ContextTypeName BookBuyersGuideMVC.Models.UsersContext.
PM> Enable-Migrations -ContextTypeName BookBuyersGuideMVC.DAL.GuideContext
Checking if the context targets an existing database...
Code First Migrations enabled for project BookBuyersGuideMVC.
PM> Enable-Migrations -ContextTypeName BookBuyersGuideMVC.Models.UsersContext
Migrations have already been enabled in project 'BookBuyersGuideMVC'. To overwrite the existing migrations configuration, use the -Force parameter.
PM> add-migration InitialCreate
Scaffolding migration 'InitialCreate'.
The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration 201403300547572_InitialCreate' again.

A file ____InitialCreate.cs was generated:

namespace BookBuyersGuideMVC.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Books",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Title = c.String(),
                        ISBN = c.String(),
                        Description = c.String(),
                        Image = c.String(),
                        DateCreated = c.DateTime(nullable: false),
                        AuthorID = c.String(),
                        MetaTitle = c.String(),
                        MetaDescription = c.String(),
                        MetaKeywords = c.String(),
                        Slug = c.String(),
                        Author_ID = c.Int(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Authors", t => t.Author_ID)
                .Index(t => t.Author_ID);
            CreateTable(
                "dbo.Authors",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        AuthorName = c.String(),
                        AuthorBio = c.String(),
                        AuthorImage = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            CreateTable(
                "dbo.CategoryAssigmments",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        BookID = c.Int(nullable: false),
                        CategoryID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Books", t => t.BookID, cascadeDelete: true)
                .ForeignKey("dbo.Categories", t => t.CategoryID, cascadeDelete: true)
                .Index(t => t.BookID)
                .Index(t => t.CategoryID);
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        CategoryName = c.String(),
                        Slug = c.String(),
                    })
                .PrimaryKey(t => t.ID);
        }
        public override void Down()
        {
            DropIndex("dbo.CategoryAssigmments", new[] { "CategoryID" });
            DropIndex("dbo.CategoryAssigmments", new[] { "BookID" });
            DropIndex("dbo.Books", new[] { "Author_ID" });
            DropForeignKey("dbo.CategoryAssigmments", "CategoryID", "dbo.Categories");
            DropForeignKey("dbo.CategoryAssigmments", "BookID", "dbo.Books");
            DropForeignKey("dbo.Books", "Author_ID", "dbo.Authors");
            DropTable("dbo.Categories");
            DropTable("dbo.CategoryAssigmments");
            DropTable("dbo.Authors");
            DropTable("dbo.Books");
        }
    }
}

Update the database:

PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying code-based migrations: [201403300547572_InitialCreate].
Applying code-based migration: 201403300547572_InitialCreate.
Running Seed method.
PM>