title: EF5 Getting this error message: Model compatibility cannot be checked because the database does not contain model metadata
body: <p>I have this error message that keeps on displaying every time I run the application. I'm using Entity <code>Framework 5: Code First</code></p>
  
  <p>Here's the error message,</p>
  
  <pre><code>System.NotSupportedException: Model compatibility cannot be checked because the database does not contain model metadata. Model compatibility can only be checked for databases created using Code First or Code First Migrations.
     at System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata)
     at System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata)
     at System.Data.Entity.Database.CompatibleWithModel(Boolean throwIfNoMetadata)
     at System.Data.Entity.DropCreateDatabaseIfModelChanges`1.InitializeDatabase(TContext context)
     at System.Data.Entity.Database.&lt;&gt;c__DisplayClass2`1.&lt;SetInitializerInternal&gt;b__0(DbContext c)
     at System.Data.Entity.Internal.InternalContext.&lt;&gt;c__DisplayClass8.&lt;PerformDatabaseInitialization&gt;b__6()
     at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
     at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
     at System.Data.Entity.Internal.LazyInternalContext.&lt;InitializeDatabase&gt;b__4(InternalContext c)
     at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
     at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
     at System.Data.Entity.Internal.InternalContext.Initialize()
     at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
     at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
     at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
     at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
     at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
     at System.Data.Entity.DbSet`1.Add(TEntity entity)
     at LaundryService_DEMO.frmMain.btnCreate_Click(Object sender, EventArgs e) in d:\MyDocs\Visual Studio 2012\Projects\LaundryService_DEMO\LaundryService_DEMO\frmMain.cs:line 39
  </code></pre>
  
  <p>This error started when I created an entity called invoice. Here's the full code of the entity,</p>
  
  <pre><code>public class Invoice
  {
      public string InvoiceID { get; set; }
      public string CustomerID { get; set; }
      public string UserID { get; set; }
      public decimal TotalAmount { get; set; }
      public DateTime TransactionDate { get; set; }
      public DateTime PaymentDate { get; set; }
  
      public Customer CustomerField { get; set; }
      public SystemUser SystemUserField { get; set; }
  }
  
  public class InvoiceMap : EntityTypeConfiguration&lt;Invoice&gt;
  {
      public InvoiceMap()
      {
          // Primary Key
          this.HasKey(x =&gt; x.InvoiceID);
  
          // Property(ies) and Mapping(s)
          this.ToTable("Invoice");
  
          this.Property(x =&gt; x.InvoiceID)
              .IsRequired()
              .HasMaxLength(15)
              .HasColumnName("InvoiceID")
              .HasColumnType("nVarchar");
  
          this.Property(x =&gt; x.CustomerID)
              .IsRequired()
              .HasMaxLength(15)
              .HasColumnName("CustomerID")
              .HasColumnType("nVarchar");
  
          this.Property(x =&gt; x.UserID)
              .IsRequired()
              .HasMaxLength(15)
              .HasColumnName("UserID")
              .HasColumnType("nVarchar");
  
          this.Property(x =&gt; x.TotalAmount)
              .IsRequired()
              .HasColumnName("TotalAmount")
              .HasColumnType("decimal");
  
          this.Property(x =&gt; x.TransactionDate)
              .IsRequired()
              .HasColumnName("TransactionDate")
              .HasColumnType("datetime");
  
          this.Property(x =&gt; x.PaymentDate)
              .IsOptional()
              .HasColumnName("PaymentDate")
              .HasColumnType("datetime");
  
          // Relationship
          this.HasRequired(x =&gt; x.CustomerField)
              .WithMany(x =&gt; x.InvoiceCollection)
              .HasForeignKey(y =&gt; y.CustomerID);
  
          this.HasRequired(x =&gt; x.SystemUserField)
              .WithMany(x =&gt; x.InvoiceCollection)
              .HasForeignKey(y =&gt; y.UserID);
      }
  }
  </code></pre>
  
  <p>In order to replicate the application, I have included the project file which is <a href="https://dl.dropbox.com/u/16021179/LaundryService_DEMO.rar" rel="noreferrer">available for download</a>. And so this question will not be full of code.</p>
  
  <p>If there are details that I've missed in the question, please comment so I can include it. </p>