title: Why am I getting this "Invalid object name 'dbo.*'" error with MVC4?
body: <p>I get this error:</p>
  
  <blockquote>
    <p>Invalid object name 'dbo.ImageMetas'.</p>
  </blockquote>
  
  <p>On this line:</p>
  
  <blockquote>
    <p>return View(db.Images.ToList());</p>
  </blockquote>
  
  <p>Where my database context looks like this:</p>
  
  <pre><code>public class GalleryContext : DbContext
  {
      public GalleryContext()
          : base("DefaultConnection")
      {
      }
  
      public DbSet&lt;ImageMeta&gt; Images { get; set; }
      public DbSet&lt;ImageFile&gt; ImageFiles { get; set; }
  }
  </code></pre>
  
  <p>And my model:</p>
  
  <pre><code>public class ImageMeta
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
      public UserProfile User { get; set; }
      public string Name { get; set; }
      public virtual ICollection&lt;ImageFile&gt; Files { get; set; } 
  }
  </code></pre>
  
  <p>It's a brand new MVC4 project. I wrote the models first, then auto-generated the controller.</p>
  
  <p>I <a href="https://stackoverflow.com/a/5310619/65387">inspected the database</a>, and indeed the table is missing.</p>
  
  <p>I was under the impression that it would auto-create the table for me though; as <a href="http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/accessing-your-models-data-from-a-controller" rel="nofollow noreferrer">this tutorial</a> suggests.</p>
  
  <p>So why isn't it doing that?</p>
  
  <hr>
  
  <p>Okay, if I add a connection string named after my context (and remove the base constructor), it works now. Why can't I use the DefaultConnection, then?</p>
  
  <pre><code>&lt;add name="GalleryContext"
     connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\gallery.mdf;Integrated Security=True"
     providerName="System.Data.SqlClient"
  /&gt;
  </code></pre>