0

Initial migration code is below where I never create dbo.StudentEvent1 but I get error when I run my asp.net MVC application using this database.

CreateTable(
            "dbo.StudentEvents",
            c => new
                {
                    StudentId = c.Int(nullable: false),
                    EventId = c.Int(nullable: false),
                    isAttended = c.Boolean(nullable: false),
                })
            .PrimaryKey(t => new { t.StudentId, t.EventId })
            .ForeignKey("dbo.Events", t => t.EventId, cascadeDelete: true)
            .ForeignKey("dbo.Students", t => t.StudentId, cascadeDelete: true)
            .Index(t => t.StudentId)
            .Index(t => t.EventId);

        CreateTable(
            "dbo.TeacherEvents",
            c => new
                {
                    TeacherId = c.Int(nullable: false),
                    EventId = c.Int(nullable: false),
                    Duties = c.String(),
                })
            .PrimaryKey(t => new { t.TeacherId, t.EventId })
            .ForeignKey("dbo.Events", t => t.EventId, cascadeDelete: true)
            .ForeignKey("dbo.Teachers", t => t.TeacherId, cascadeDelete: true)
            .Index(t => t.TeacherId)
            .Index(t => t.EventId);
Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Yasir
  • 1
  • 1

1 Answers1

0

Open your package manager console and Select Default project

then Enable-Migrations is use for Enable Migrations then add-migrations is added your changes in Migrations then Update-Database is apply to database

please refer below link : http://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx

thanks

Parin Patel
  • 312
  • 1
  • 2
  • 8