简体   繁体   中英

Update-database problem in asp.net MVC application

When i update database in package manager console i have this error

Introducing FOREIGN KEY constraint 'FK_dbo.Appointments_dbo.Users_AppointmentManagerId' on table 'Appointments' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint or index. See previous errors.

My classes

   [Table("Appointments")]
    public class Appointment
    {
        #region property 

            [Key]
            public int Id { get; set; }
            [Required]
            [MaxLength(200)]
            public string Subject { get; set; }
            [Required]
            [MaxLength(500)]
            public string Description { get; set; }
            [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy hh:mm tt")]
            public DateTime StarTime { get; set; }
            [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy hh:mm tt")]
            public DateTime EndTime { get; set; }
            public String Location { get; set; }

        #endregion
        #region relationship

            [ForeignKey("AppointmentCustomer")]
            public int AppointmentCustomerId { get; set; }
            [ForeignKey("AppointmentManager")]
            public int AppointmentManagerId { get; set; }
            public virtual Users AppointmentCustomer { get; set; }
            public virtual Users AppointmentManager { get; set; }

        #endregion
    }



 [Table("Users")]
    public class Users
    {
        #region property 

            [Key]
            public int Id { get; set; }
            [Required]
            public string IDUser { get; set; }
            [Required]
            public string Email { get; set; }

        #endregion
        #region relationship

            [InverseProperty("TicketDeveloper")]
            public virtual ICollection<Ticket> TicketDevelopers { get; set; }  
            [InverseProperty("TicketTester")]
            public virtual ICollection<Ticket> TicketTesters { get; set; }
            [InverseProperty("ProjectCustomer")]
            public virtual ICollection<Project> ProjectCustomers { get; set; }
            [InverseProperty("ProjectManager")]
            public virtual ICollection<Project> ProjectManagers { get; set; }
            [InverseProperty("NoteTester")]
            public virtual ICollection<Note> NoteTesters { get; set; }
            [InverseProperty("CaseCustomer")]
            public virtual ICollection<Case> CaseCustomers { get; set; }
            [InverseProperty("AppointmentCustomer")]
            public virtual ICollection<Appointment> AppointmentCustomers { get; set; }
            [InverseProperty("AppointmentManager")]
            public virtual ICollection<Appointment> AppointmentManagers { get; set; }

        #endregion
}

okay I solve the problem make int? in foreign key

        [ForeignKey("AppointmentCustomer")]
        public int? AppointmentCustomerId { get; set; }
        [ForeignKey("AppointmentManager")]
        public int? AppointmentManagerId { get; set; }
        public virtual Users AppointmentCustomer { get; set; }
        public virtual Users AppointmentManager { get; set; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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