繁体   English   中英

无法使用更新数据库MVC4

[英]Unable to use update-database MVC4

我正在尝试使用Code First EF 6将我的MVC4模型迁移到数据库。运行“ update-database”命令时,出现错误消息

为表“会议”指定了多个标识列。 每个表只允许一个标识列。

我查看了Migration文件,并尝试在语句周围移动,以使它们不会试图在一个表上添加2个标识列并得到此信息。

无法找到对象“ dbo.foo”,因为它不存在或您没有权限。

所以我想接下来要尝试的是删除所有enable-migrations -contexttypename整个过程,当我尝试enable-migrations -contexttypename命令时,得到了这个

检测到的使用数据库初始化程序创建的数据库

当我查看初始迁移时,它看起来像我在获得项目的其他部分之前最初使用的迁移,但是缺少一些模型。 然后,当我添加迁移时,我的问题将从本文开头重复。

我已经用尽了关于MVC4的所有知识,而我的老师对帮助解决这个问题并没有表现出太大兴趣。 有人可以提供一些见识吗?

这是模特

public class Conference
{
    [Key]
    public int conferenceID { get; set; }
    public string username { get; set; }
    public string Title { get; set; }
    public DateTime StartDate { get; set; }
    public DateTime EndDate { get; set; }
    public string Topic { get; set; }
    public virtual ICollection<Sponsor> Sponsors{ get; set; }
    public string Description { get; set; }
    public int Rating { get; set; }
    public string Location { get; set; }
    public bool Active { get; set; }
    public virtual ICollection<Session> Sessions { get; set; }
}

我删除了所有的html和验证元标记,以使其更易于阅读

可能是您的DbContext类中的配置不同,或者是您的DbContext类的OnModelCreating方法中的EntityTypeConfiguration类。

这可能只是因为您使用了PK。

尝试以下操作: 相同问题,但在EF5上

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM