0

Im having some issues trying to deploy a code first based mvc4 application to azure.

It works fine when creating a localdb however when trying to deploy to azure the UserProfile table only Username & UserId fields are created.

My model looks like

[Table("UserProfile")]
public class UserProfile
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }

    public Guid ConsumerId { get; set; }
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Email { get; set; }
    public bool IsMale { get; set; }
    public string Mobile { get; set; }
    [DefaultValue(false)]
    public bool IsSmsVerified { get; set; }
    public string SmsVerificationCode { get; set; }

}

Context

  public class UsersContext : DbContext
{
    public UsersContext()
        : base("DefaultConnection")
    {
    }

    public DbSet<UserProfile> UserProfiles { get; set; }
    public DbSet<ExternalUserInformation> ExternalUsers { get; set; }
}

Configuration

 internal sealed class Configuration : DbMigrationsConfiguration<Web.Models.UsersContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(Web.Models.UsersContext context)
    {
        //  This method will be called after migrating to the latest version.

        //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
        //  to avoid creating duplicate seed data. E.g.
        //
        //    context.People.AddOrUpdate(
        //      p => p.FullName,
        //      new Person { FullName = "Andrew Peters" },
        //      new Person { FullName = "Brice Lambson" },
        //      new Person { FullName = "Rowan Miller" }
        //    );
        //

        WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

Is there a magic switch somewhere that I need to turn on?

7
  • What database initialization strategy are you using? I'm thinking that you might have it set to something like CreateDatabaseIfNotExists or something equivalent. Commented Jun 11, 2013 at 3:16
  • Can you show your DataContext class?
    – user751651
    Commented Jun 11, 2013 at 3:32
  • hi Richard the database is created in azure its just missing some of the fields. @hbrock I've updated my post
    – Diver Dan
    Commented Jun 11, 2013 at 3:54
  • @DiverDan, have you looked at this link: windowsazure.com/en-us/develop/net/tutorials/…
    – user751651
    Commented Jun 11, 2013 at 3:58
  • @DiverDan ~ yeap. Could you check what your database initialization strat is? Because if it's something like CreateDatabaseIfNotExists, then it's definitely going to be created the first time, but it won't be updated if your model changes somehow (which could account for the missing fields). Commented Jun 11, 2013 at 4:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.