1

How do I debug an error with my Entity Framework Code First database deployment?

I'm using EF 6.1.3. I'm trying to deploy a database to Azure that includes the following model:

public class DriverLog
{
    public int ID { get; set; }

    [Required]
    public DateTime LogDate { get; set; }

    public int RouteID { get; set; }
    public virtual Route Route { get; set; }

    public int DriverID { get; set; }
    [ForeignKey("DriverID")]
    public virtual Employee Driver { get; set; }

    public int DispatcherID { get; set; }
    [ForeignKey("DispatcherID")]
    public virtual Employee Dispatcher { get; set; }
}

The deployment succeeds, but when I try to access the database, I get the following error:

{"Message":"An error has occurred."}

If I remove the last two fields -- DispatcherID and Dispatcher -- I do not get this error.

For some reason, EF does not like my including these two fields, but I don't know why, and I don't know how to go about debugging this.

Mike Taverne
  • 9,156
  • 2
  • 42
  • 58

2 Answers2

1

I was able to resolve the problem like this:

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
         modelBuilder.Entity<DriverLog>()
            .HasRequired(o => o.Dispatcher)
            .WithMany()
            .WillCascadeOnDelete(false);
    }

Credit for this solution goes to: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths - why?

Community
  • 1
  • 1
Mike Taverne
  • 9,156
  • 2
  • 42
  • 58
-1

Do check primary key constraint for 'DispatcherID', basicaly the order its creating the table, as you are using 'DropCreateDatabaseIfModelChanges'.

Also inject some custom error catch, to have detail error information.

Kasam Shaikh
  • 319
  • 2
  • 6