'PK_dbo.EntityName' is not a constraint. Could not drop constraint.EF6

code-first entity-framework-6

Question

I'm starting with Entity Framework 6 code. I have three of these entities:

public class Doctor
{
    public string DoctorID { get; set; } 
    public string firstName { get; set; }
    public string lastName { get; set; }
 }

public class ExpertiseDetails
{
    [Key, Column(Order = 1)]
    public short expertiseID { get; set; }
    [Key , Column(Order = 2)]
    public string DoctorID { get; set; }

    [ForeignKey("expertiseID")]
    public Expertise expertise { get; set; }
    public Doctor doctor { get; set; }
}


public class Expertise
{
    [Key]
    public short expertiseID { get; set; }
    public string expertiseTitle { get; set; }
}

I want aone to many the connection betweenExpertise and Doctor , When I do the update-database command in the consolenuGet this error manifests:

'PK_dbo.ExpertiseDetails' is not a constraint. Could not drop constraint

What's the issue?

1
3
8/20/2016 8:17:49 PM

Popular Answer

After running into a similar problem after modifying the table structure, I fixed it by using sql to specifically remove the PK name.

In my situation, the problem started after renaming the table schema and changing a primary key in a table:

Original:

  • PK-named dbo.LogEntries: PK dbo.LogEntries

Schema modification in phase 1

  • Logging. Log entries with a constant PK

Step 2: Change the PK

  • PK changed: results inDropPrimaryKey("Logging.LogEntries");

This last line translates to the PK-name:PK_Logging.LogEntries it is nonexistent.

a remedy: There are numerous ways to remedy this generally. Through a sql-statement in the explicit migration, I deleted the PK.

Sql("ALTER TABLE [Logging].[LogEntries] DROP CONSTRAINT [PK_dbo.LogEntries]");

Be warned: I didn't utilise migrations to roll back to a prior state, but I did have full access to the production environment in case it failed.

3
9/4/2016 2:28:10 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow