title: The required property {0} does not exist on the type {1}. Entity framework (model first) when adding FK
body: <p>I am trying to add foreign key to the database and then I am updating the model. After I update the model, the application gives following error:</p>
  
  <pre><code>System.Data.Entity.Core.MetadataException was unhandled
    HResult=-2146232007
    Message=Schema specified is not valid. Errors: 
  The relationship 'Accounting.Data.Repository.FK_np_DocumentStatuses_DocumentsTracking_StateId' was not loaded because the type 'Accounting.Data.Repository.DocumentsTracking' is not available.
  The following information may be useful in resolving the previous error:
  The required property 'DocumentsTrackingChildDocuments' does not exist on the type 'Accounting.Entity.DocumentsTracking'.
  
  
  The relationship 'Accounting.Data.Repository.FK_np_DocumentsTracking_DocumentsTrackingChildDocuments_DocumentsTrackingId' was not loaded because the type 'Accounting.Data.Repository.DocumentsTracking' is not available.
  The following information may be useful in resolving the previous error:
  The required property 'DocumentsTrackingChildDocuments' does not exist on the type 'Accounting.Entity.DocumentsTracking'.
  
  
    Source=EntityFramework
    StackTrace:
         at System.Data.Entity.Core.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
         at System.Data.Entity.Core.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action`1 logLoadMessage)
         at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action`1 logLoadMessage)
         at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly, Action`1 logLoadMessage)
         at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly)
         at System.Data.Entity.Core.Metadata.Edm.MetadataOptimization.TryUpdateEntitySetMappingsForType(Type entityType)
         at System.Data.Entity.Internal.InternalContext.TryUpdateEntitySetMappingsForType(Type entityType)
         at System.Data.Entity.Internal.InternalContext.UpdateEntitySetMappingsForType(Type entityType)
         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.GetEnumerator()
         at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable&lt;TResult&gt;.GetEnumerator()
         at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
         at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
         at Accounting.Data.Logic.OrdersLogic.getOrdersTmpList() in f:\proj\Accounting.Data.Logic\OrdersLogic.cs:line 16
         at Accounting.Data.Logic.OrdersLogic.RefreshDocumentsFromTmpOrders() in f:\proj\Accounting.Data.Logic\OrdersLogic.cs:line 22
         at Accounting.UI.MainForm.btnRefreshDocumentsFromOrderTmp_Click(Object sender, EventArgs e) in f:\proj\Accounting.UI\MainForm.cs:line 57
         at System.Windows.Forms.Control.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnClick(EventArgs e)
         at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
         at System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons button, Int32 clicks)
         at System.Windows.Forms.Control.WndProc(Message&amp; m)
         at System.Windows.Forms.ButtonBase.WndProc(Message&amp; m)
         at System.Windows.Forms.Button.WndProc(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
         at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp; m)
         at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
         at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
         at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
         at System.Windows.Forms.Application.Run(Form mainForm)
         at Accounting.UI.Program.Main() in f:\proj\Accounting.UI\Program.cs:line 19
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException:
  </code></pre>
  
  <p>My entities:</p>
  
  <pre><code>namespace Iwatch.Accounting.Entity
  {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      using System.Xml.Serialization;
  
  
      public partial class DocumentStatus 
      {
          public DocumentStatus()
          {
              this.Documents = new HashSet&lt;Document&gt;();
              this.DocumentsTrackings = new HashSet&lt;DocumentsTracking&gt;();
              this.DocumentsTrackingChildDocuments = new HashSet&lt;DocumentsTrackingChildDocument&gt;();
          }
          [XmlElement("StateId")]
          [Key] 
          public int StateId { get; set; }
          [XmlElement("StateName")]
          public string StateName { get; set; }
          [XmlElement("GroupId")]
          public Nullable&lt;int&gt; GroupId { get; set; }
  
          public virtual HashSet&lt;Document&gt; Documents { get; set; }
          public virtual HashSet&lt;DocumentsTracking&gt; DocumentsTrackings { get; set; }
          public virtual HashSet&lt;DocumentsTrackingChildDocument&gt; DocumentsTrackingChildDocuments { get; set; }
      }
  }
  
  //------------------------------------------------------------------------------
  // &lt;auto-generated&gt;
  //     This code was generated from a template.
  //
  //     Manual changes to this file may cause unexpected behavior in your application.
  //     Manual changes to this file will be overwritten if the code is regenerated.
  // &lt;/auto-generated&gt;
  //------------------------------------------------------------------------------
  
  namespace Iwatch.Accounting.Entity
  {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      using System.Globalization;
      using System.Xml.Serialization;
  
      public partial class DocumentsTracking
      {
          [XmlIgnore]
          CultureInfo culture = CultureInfo.CreateSpecificCulture("de-LI");
  
          [XmlIgnore]
          public int Id { get; set; }
          [Key]
          [XmlElement("Barcode")]
          public string Barcode { get; set; }
          [XmlElement("StateId")]
          public Nullable&lt;int&gt; StateId { get; set; }
          [XmlElement("StateName")]
          public string StateName { get; set; }
          [XmlElement("CheckWeight")]
          public Nullable&lt;decimal&gt; CheckWeight { get; set; }
          [XmlElement("DocumentCost")]
          public Nullable&lt;decimal&gt; DocumentCost { get; set; }
  
          [XmlIgnore]
          public DateTime? DateReceived { get; set; }
  
          [XmlElement("DateReceived")]
          public string DateReceivedString
          {
              get { return this.DateReceived != null ? this.DateReceived.Value.ToString("dd.MM.yyyy hh:mm:ss") : ""; }
              set { this.DateReceived = (value.Equals("") ? (DateTime?)null : System.DateTime.Parse(value, culture)); }
          }
  
          [XmlElement("RecipientFullName")]
          public string RecipientFullName { get; set; }
          [XmlElement("RecipientPost")]
          public string RecipientPost { get; set; }
          [XmlIgnore]
          public DateTime? ReceiptDateTime { get; set; }
  
          [XmlElement("ReceiptDateTime")]
          public string ReceiptDateTimeString
          {
              get { return this.ReceiptDateTime != null ? this.ReceiptDateTime.Value.ToString("yyyy-MM-dd hh:mm:ss") : ""; }
              set { this.ReceiptDateTime = (value.Equals("") ? (DateTime?)null : System.DateTime.Parse(value)); }
          }
          [XmlElement("OnlinePayment")]
          public Nullable&lt;bool&gt; OnlinePayment { get; set; }
          [XmlElement("DeliveryForm")]
          public Nullable&lt;int&gt; DeliveryForm { get; set; }
          [XmlElement("AddressUA")]
          public string AddressUA { get; set; }
          [XmlElement("AddressRU")]
          public string AddressRU { get; set; }
          [XmlElement("WareReceiverId")]
          public Nullable&lt;int&gt; WareReceiverId { get; set; }
          [XmlElement("BackDelivery")]
          public Nullable&lt;int&gt; BackDelivery { get; set; }
          [XmlElement("RedeliveryNUM")]
          public string RedeliveryNUM { get; set; }
          [XmlElement("CityReceiverSiteKey")]
          public Nullable&lt;int&gt; CityReceiverSiteKey { get; set; }
          [XmlElement("CityReceiverUA")]
          public string CityReceiverUA { get; set; }
          [XmlElement("CityReceiverRU")]
          public string CityReceiverRU { get; set; }
          [XmlElement("CitySenderSiteKey")]
          public Nullable&lt;int&gt; CitySenderSiteKey { get; set; }
          [XmlElement("CitySenderUA")]
          public string CitySenderUA { get; set; }
          [XmlElement("CitySenderRU")]
          public string CitySenderRU { get; set; }
          [XmlElement("DeliveryType")]
          public string DeliveryType { get; set; }
          [XmlElement("BackwardDeliveryNumber")]
          public System.Guid BackwardDeliveryNumber { get; set; }
          [XmlElement("RedeliveryCargoDescriptionMoney")]
          public string RedeliveryCargoDescriptionMoney { get; set; }
          [XmlElement("Failure")]
          public Nullable&lt;bool&gt; Failure { get; set; }
          [XmlElement("ReasonDescription")]
          public string ReasonDescription { get; set; }
          [XmlElement("GlobalMoneyExistDelivery")]
          public Nullable&lt;bool&gt; GlobalMoneyExistDelivery { get; set; }
          [XmlElement("GlobalMoneyLastTransactionStatus")]
          public string GlobalMoneyLastTransactionStatus { get; set; }
          [XmlIgnore]
          public DateTime? GlobalMoneyLastTransactionDate { get; set; }
  
          [XmlElement("GlobalMoneyLastTransactionDate")]
          public string GlobalMoneyLastTransactionDateString
          {
              get { return this.GlobalMoneyLastTransactionDate != null ? this.GlobalMoneyLastTransactionDate.Value.ToString("yyyy-MM-dd hh:mm:ss") : ""; }
              set { this.GlobalMoneyLastTransactionDate = (value.Equals("") ? (DateTime?)null : System.DateTime.Parse(value)); }
          }
          [XmlElement("Sum")]
          public Nullable&lt;decimal&gt; Sum { get; set; }
          [XmlElement("DocumentWeight")]
          public Nullable&lt;decimal&gt; DocumentWeight { get; set; }
  
          //TODO: the right data type is supposed to be used
          [XmlIgnore] //[XmlElement("SumBeforeCheckWeight")]
          public Nullable&lt;decimal&gt; SumBeforeCheckWeight { get; set; }
          [XmlElement("isEWPaid")]
          public Nullable&lt;bool&gt; isEWPaid { get; set; }
          [XmlElement("isEWPaidCashLess")]
          public Nullable&lt;bool&gt; isEWPaidCashLess { get; set; }
          [XmlElement("ewPaidSumm")]
          public Nullable&lt;decimal&gt; ewPaidSumm { get; set; }
          [XmlElement("RedeliverySum")]
          public Nullable&lt;decimal&gt; RedeliverySum { get; set; }
          [XmlElement("OwnerDocumentType")]
          public string OwnerDocumentType { get; set; }
          [XmlElement("errors")]
          public string errors { get; set; }
          [XmlElement("warnings")]
          public string warnings { get; set; }
          [XmlElement("info")]
          public string info { get; set; }
  
          public virtual DocumentStatus DocumentStatus { get; set; }
          public virtual DocumentsTrackingChildDocument DocumentsTrackingChildDocument { get; set; }
      }
  }
  
  //------------------------------------------------------------------------------
  // &lt;auto-generated&gt;
  //     This code was generated from a template.
  //
  //     Manual changes to this file may cause unexpected behavior in your application.
  //     Manual changes to this file will be overwritten if the code is regenerated.
  // &lt;/auto-generated&gt;
  //------------------------------------------------------------------------------
  
  namespace Iwatch.Accounting.Entity
  {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      using System.Xml.Serialization;
  
      public partial class DocumentsTrackingChildDocument
      {
  
          public int Id { get; set; }
          [XmlElement("DocumentsTrackingId")]
          [Key]
          public Nullable&lt;int&gt; DocumentsTrackingId { get; set; }
          [XmlElement("Barcode")]
          public string Barcode { get; set; }
          [XmlElement("StateId")]
          public Nullable&lt;int&gt; StateId { get; set; }
          [XmlElement("StateName")]
          public string StateName { get; set; }
          [XmlElement("CheckWeight")]
          public Nullable&lt;decimal&gt; CheckWeight { get; set; }
          [XmlElement("DocumentCost")]
          public Nullable&lt;decimal&gt; DocumentCost { get; set; }
          [XmlElement("DateReceived")]
          public Nullable&lt;System.DateTime&gt; DateReceived { get; set; }
          [XmlElement("RecipientFullName")]
          public string RecipientFullName { get; set; }
          [XmlElement("RecipientPost")]
          public string RecipientPost { get; set; }
          [XmlElement("ReceiptDateTime")]
          public Nullable&lt;System.DateTime&gt; ReceiptDateTime { get; set; }
          [XmlElement("OnlinePayment")]
          public Nullable&lt;bool&gt; OnlinePayment { get; set; }
          [XmlElement("DeliveryForm")]
          public string DeliveryForm { get; set; }
          [XmlElement("AddressUA")]
          public string AddressUA { get; set; }
          [XmlElement("AddressRU")]
          public string AddressRU { get; set; }
          [XmlElement("WareReceiverId")]
          public Nullable&lt;int&gt; WareReceiverId { get; set; }
          [XmlElement("BackDelivery")]
          public string BackDelivery { get; set; }
          [XmlElement("RedeliveryNUM")]
          public string RedeliveryNUM { get; set; }
          [XmlElement("CityReceiverSiteKey")]
          public string CityReceiverSiteKey { get; set; }
          [XmlElement("CityReceiverUA")]
          public string CityReceiverUA { get; set; }
          [XmlElement("CityReceiverRU")]
          public string CityReceiverRU { get; set; }
          [XmlElement("CitySenderSiteKey")]
          public string CitySenderSiteKey { get; set; }
          [XmlElement("CitySenderUA")]
          public string CitySenderUA { get; set; }
          [XmlElement("CitySenderRU")]
          public string CitySenderRU { get; set; }
          [XmlElement("DeliveryType")]
          public string DeliveryType { get; set; }
          [XmlElement("BackwardDeliveryNumber")]
          public System.Guid BackwardDeliveryNumber { get; set; }
          [XmlElement("RedeliveryCargoDescriptionMoney")]
          public string RedeliveryCargoDescriptionMoney { get; set; }
          [XmlElement("Failure")]
          public Nullable&lt;bool&gt; Failure { get; set; }
          [XmlElement("ReasonDescription")]
          public string ReasonDescription { get; set; }
          [XmlElement("GlobalMoneyExistDelivery")]
          public Nullable&lt;bool&gt; GlobalMoneyExistDelivery { get; set; }
          [XmlElement("GlobalMoneyLastTransactionStatus")]
          public string GlobalMoneyLastTransactionStatus { get; set; }
          [XmlElement("GlobalMoneyLastTransactionDate")]
          public Nullable&lt;System.DateTime&gt; GlobalMoneyLastTransactionDate { get; set; }
          [XmlElement("Sum")]
          public Nullable&lt;decimal&gt; Sum { get; set; }
          [XmlElement("DocumentWeight")]
          public Nullable&lt;decimal&gt; DocumentWeight { get; set; }
          [XmlElement("SumBeforeCheckWeight")]
          public Nullable&lt;decimal&gt; SumBeforeCheckWeight { get; set; }
          [XmlElement("isEWPaid")]
          public Nullable&lt;bool&gt; isEWPaid { get; set; }
          [XmlElement("isEWPaidCashLess")]
          public Nullable&lt;bool&gt; isEWPaidCashLess { get; set; }
          [XmlElement("ewPaidSumm")]
          public Nullable&lt;decimal&gt; ewPaidSumm { get; set; }
          [XmlElement("RedeliverySum")]
          public Nullable&lt;decimal&gt; RedeliverySum { get; set; }
          [XmlElement("OwnerDocumentType")]
          public string OwnerDocumentType { get; set; }
  
          public virtual DocumentStatus DocumentStatus { get; set; }
          public virtual DocumentsTracking DocumentsTracking { get; set; }
      }
  }
  </code></pre>
  
  <p>What do I miss?</p>