Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 Project - cannot DropCreateDatabaseIfModelChanges
    primarykey
    data
    text
    <p>I have an MVC4 internet application using forms authentication.</p> <p>Out of the box the <code>UserProfile</code> model is created in the Account models file, I have moved that to its own file and called <code>DbSet&lt;UserProfile</code>> in my <code>DbContext</code> file. I expected EF to create a 2 table database, UserProfiles and Stories.</p> <pre><code>public class MySocialStoriesDb : DbContext { public DbSet&lt;UserProfile&gt; UserProfiles { get; set; } public DbSet&lt;Story&gt; Stories { get; set; } } </code></pre> <p>Story Model</p> <pre><code>[Table("Stories")] public class Story { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int StoryId { get; set; } public int UserId { get; set; } [ForeignKey("UserId")] public virtual UserProfile User { get; set; } public string File { get; set; } public DateTime DateCreated { get; set; } public string Name { get; set; } } </code></pre> <p>UserProfile Model</p> <pre><code>[Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } public string EmailAddress { get; set; } public string UserDirectory { get; set; } public bool Paid { get; set; } public DateTime DatePaid { get; set; } public string PaymentId { get; set; } } </code></pre> <p>I have run Enable-Migrations from Package Manager and allowed automatic migrations and allowed dataloss. The InitialCreate file generated only seems to create the User Profile table, it doesn't have anything in its code for the Story table.</p> <p>I added the following line to Global.asax</p> <pre><code>Database.SetInitializer(new Models.IntializeMySocialStoriesDb()); </code></pre> <p>If i now change a model nothing on the database changes. If i manually drop the database and change the <code>InitializeMySocialStoriesDb</code> to DropCreateDatabaseAlways and then run the app, the database is not created.</p> <p>I am just wondering what I have missed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload