title: Npgsql.PostgresException: 42P01: relation "table" does not exist
body: <p>I have a problem when I'm trying put data in a table "AccomodationCategories" with a many to many relationship but I'm getting the error:</p>
  
  <p>Npgsql.PostgresException: 42P01: relation "AccomodationCategories" does not exist</p>
  
  <p>So this is what my tables look like:</p>
  
  <p><a href="https://i.stack.imgur.com/jBo5C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jBo5C.png" alt="enter image description here"></a></p>
  
  <p>As I'm saving my "Accomodations" I'm selecting a category from my "Category" table in a dropdown. But when I hit update it gives an error.</p>
  
  <p>This is my code in my AccomodationController:</p>
  
  <pre><code>[HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Edit(AccomodationDetailViewModel model, Int16 id)
          {
              var alert = new Alert();
  
  
              try 
              {
                  if(!ModelState.IsValid)
                  {
                      alert.Message = alert.ExceptionMessage = ApplicationDbContextMessage.INVALID;
                      throw new Exception();
                  }    
  
                  var originalModel = ApplicationDbContext.AccomodationDetails.FirstOrDefault(m =&gt; m.Id == model.AccomodationDetail.Id);
  
                  //AccomodationCategories
                  var modelC = await ApplicationDbContext.AccomodationCategories.FirstOrDefaultAsync(m =&gt; m.AccomodationId == id);
                  var modelC2 = await ApplicationDbContext.AccomodationCategories.FirstOrDefaultAsync(m =&gt; m.CategoryId == id);
  
                  var accoCat1 = ApplicationDbContext.AccomodationCategories.FirstOrDefault(m =&gt; m.AccomodationId == modelC.Accomodations.Id);
                  var accoCat2 = ApplicationDbContext.AccomodationCategories.FirstOrDefault(m =&gt; m.CategoryId == modelC2.Categories.Id);  
                  //
  
                  if(originalModel == null) 
                  {
                      alert.Message = alert.ExceptionMessage = ApplicationDbContextMessage.NOTEXISTS;
                      throw new Exception();
                  }
  
                  originalModel.Title = model.AccomodationDetail.Title;
                  originalModel.Description = model.AccomodationDetail.Description;
                  originalModel.RentalTypeId = model.AccomodationDetail.RentalTypeId;
  
                  //AccomodationCategories
                  accoCat1.AccomodationId = modelC.AccomodationId;
                  accoCat2.CategoryId = modelC2.CategoryId;
  
                  ApplicationDbContext.AccomodationCategories.Attach(accoCat1);
                  ApplicationDbContext.AccomodationCategories.Attach(accoCat2);
                  //
  
                  ApplicationDbContext.AccomodationDetails.Attach(originalModel);
                  ApplicationDbContext.Entry(originalModel).State = EntityState.Modified;
  
                  if (await ApplicationDbContext.SaveChangesAsync() == 0)
                  {
                      alert.Message = alert.ExceptionMessage = ApplicationDbContextMessage.EDITNOK;
                      throw new Exception();
                  } 
  
                  alert.Message = ApplicationDbContextMessage.EDITOK;
                  return RedirectToAction("Index");
              }
              catch(Exception ex)
              {
                  alert.Type = AlertType.Error;
                  alert.ExceptionMessage = ex.Message;
  
                  model = await ViewModel(model.AccomodationDetail);
  
                  ModelState.AddModelError(string.Empty, alert.ExceptionMessage);
              }
              return View(model);
          }
  </code></pre>
  
  <p>This is my code in my ApplicationDbContext.cs</p>
  
  <pre><code>public DbSet&lt;AccomodationCategory&gt; AccomodationCategories { get; set; }
  
              // Many-To-Many in EF7 (10-10-2016)
              // Accomodation can have many categories
              // category can be assigned to many Accomodations
              builder.Entity&lt;AccomodationCategory&gt;()
                  .HasKey(c =&gt; new { c.AccomodationId, c.CategoryId });
  
              builder.Entity&lt;AccomodationCategory&gt;()
                  .HasOne(ac =&gt; ac.Accomodations)
                  .WithMany(p =&gt; p.Categories)
                  .HasForeignKey(ac =&gt; ac.AccomodationId);
  
              builder.Entity&lt;AccomodationCategory&gt;()
                  .HasOne(ac =&gt; ac.Categories)
                  .WithMany(a =&gt; a.Accomodations)
                  .HasForeignKey(ac =&gt; ac.CategoryId);
  </code></pre>