0

初始迁移代码低于我从未创建的位置,dbo.StudentEvent1但是当我使用此数据库运行我的 asp.net MVC 应用程序时出现错误。

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);
4

1 回答 1

0

打开你的包管理器控制台并选择默认项目

然后Enable-Migrations用于启用迁移然后add-migrations添加您在迁移中的更改然后Update-Database应用于数据库

请参考以下链接:http://www.entityframeworktutorial.net/code-first/code-based-migration-in-code-first.aspx

谢谢

于 2018-09-20T04:33:31.093 回答