title: Exception when code first tried to create database
body: <p>I've created a new ASP.NET MVC 4 application, and would like it to use code first. However it doesn't seem to initially create the database file if it doesn't exist already. If I delete the .mdf file from the App_Data folder, then I get the following exception when the app tries to access the database:</p>
  
  <pre><code>System.Data.SqlClient.SqlException: Cannot attach the file '&lt;path-to-db-file&gt;.mdf' as database '&lt;my-db-file-name&gt;'.
  </code></pre>
  
  <p>If I run it in the app in the debugger, then I can see that the exception is occurring in the InitializeSimpleMembershipAttribute::OnActionExecuting method when calling LazyInitializer.EnsureInitialized. The caught exception is:</p>
  
  <pre><code>[System.Reflection.TargetInvocationException]   {"Exception has been thrown by the target of an invocation."}   System.Reflection.TargetInvocationException
  </code></pre>
  
  <p>With an inner exception of:</p>
  
  <pre><code>[System.InvalidOperationException]  {"The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588"} System.InvalidOperationException
  </code></pre>
  
  <p>Which then has the first exception I mentioned above as the inner exception of that.</p>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I've just tried it with a brand new MVC4 app. I can replicate it by doing the following:</p>
  
  <ol>
  <li>Create the MVC app in the VS wizard.</li>
  <li>Run the app for the first time and go to the login page (note the mdf file now gets generated).</li>
  <li>Delete the mdf file, and go back to the login page. The exception is now thrown.</li>
  </ol>