Note that there are some explanatory texts on larger screens.

plurals
  1. POIndex already exists error in EF 4.3 Code First with Data Annotations
    primarykey
    data
    text
    <p>I'm trying to create a billing database with Entity Framework 4.3 using Code First with Data Annotations, and I'm getting an error every time I try to create my database. Here are the objects that I'm dealing with:</p> <pre><code>public class ClientBase { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ClientID { get; set; } [Required] public string ClientName { get; set; } [Required] public bool IsActive { get; set; } [Required] public string ClientContactName { get; set; } [Required] public string ClientContactEmail { get; set; } public virtual List&lt;PropertyBase&gt; Communities { get; set; } } public class PropertyBase { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int PropertyID { get; set; } [ForeignKey("Client")] public int ClientID { get; set; } [Required, EnumDataType(typeof(BillingFrequency))] public BillingFrequency PropertyBillingFrequency { get; set; } [Required] public bool IsActive { get; set; } [Required] public string PropertyName { get; set; } public string PropertyStreet { get; set; } public string PropertyCity { get; set; } public string PropertyState { get; set; } public int PropertyZipCode { get; set; } public virtual ClientBase Client { get; set; } } </code></pre> <p>No matter what I try to do, I always get this error: </p> <pre><code>The operation failed because an index or statistics with name 'IX_ClientID' already exists on table 'Property'. </code></pre> <p>I've seen solutions to this question with the Fluent API, but I haven't found one for Data Annotations.</p> <p>Does anyone have any idea how to fix this?</p> <p>EDIT: Here is the code in the DbContext:</p> <pre><code>public DbSet&lt;ClientBase&gt; ClientBases { get; set; } public DbSet&lt;PropertyBase&gt; PropertyBases { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;(); base.OnModelCreating(modelBuilder); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload