Migracja nie zmienia mojego stołu
Właśnie włączyłem migracje w moim projekcie i dodałem kilka pólUserProfile
:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Description { get; set;}
public DateTime? CreatedOn { get; set; }
public DateTime? LastAccess { get; set; }
}
I Add-migration AddFieldsForUserProfile
i stworzył:
...
public override void Up()
{
AddColumn("dbo.UserProfile", "Email", c => c.String());
AddColumn("dbo.UserProfile", "Description", c => c.String());
AddColumn("dbo.UserProfile", "CreatedOn", c => c.DateTime());
AddColumn("dbo.UserProfile", "LastAccess", c => c.DateTime());
}
...
Update-database -verbose
dało to wyjście:
Target database is: 'Hifi.Models.HifiContext' (DataSource: (localdb)\v11.0, Provider: System.Data.SqlClient, Origin: Convention).
Applying code-based migrations: [201303311011083_AddFieldsForUserProfile].
Applying code-based migration: 201303311011083_AddFieldsForUserProfile.
ALTER TABLE [dbo].[UserProfile] ADD [Email] [nvarchar](max)
ALTER TABLE [dbo].[UserProfile] ADD [Description] [nvarchar](max)
ALTER TABLE [dbo].[UserProfile] ADD [CreatedOn] [datetime]
ALTER TABLE [dbo].[UserProfile] ADD [LastAccess] [datetime]
[Inserting migration history record]
Running Seed method.
Najwyraźniej wszystko poszło dobrze, ale po otrzymaniu błędu, że coloumn CreatedOn nie istnieje, zajrzałem do bazy danych za pomocą Eksploratora serwera i rzeczywiście, w moim systemie brakuje wszystkich 4 kolorów.UserProfile
stół. Co zrobiłem źle?
Znalazłem mój błąd. Jakoś miałem dwa różnemdf
plikiaspnet-Hifi-20130330054424.mdf
iHifi.Models.HifiContext.mdf
który miał ten sam rozmiar pliku i założyłem, że oba są konieczne. Mój Eksplorator serwera korzystał zaspnetxx.mdf
i wprowadzono zmiany w bazie danychHifiContext.mdf
. Wstyd mi.
W powiązanej notatce miałem problemy z prawidłowym wyświetleniem listy wszystkich zarejestrowanych użytkowników. Zawsze był pusty, ale mogłem się zalogować bez zarzutu. Jakoś do logowaniaaspnetxx.mdf
był pytany, ale mójMemberListController
zapytałHifiContext.mdf
. Po zmianie ciągu połączenia początkowo nie miałem zarejestrowanych użytkowników, dodawano nowychHifiContext.mdf
a lista działała poprawnie. Jak to się stało?