Migration does not alter my table

前端 未结 2 1018
灰色年华
灰色年华 2020-12-22 01:29

I just enabled migrations in my project and added a few fields to UserProfile:

[Table(\"UserProfile\")]
public class UserProfile
{
    [Key]
            


        
相关标签:
2条回答
  • 2020-12-22 01:43

    are you sure you're looking at the right Db?
    it seems so though. Did you get any errors? Any special permissions etc.

    My advice is to create a new connection - e.g. config and

    <connectionStrings>
        <add name="HifiContext" connectionString="Data Source=MACHINE\INSTANCE;Initial Catalog=HiFi;Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    </connectionStrings>`
    

    ...and backup your old just in case. i.e. recreate Db from scratch

    If nothing works - try recreating if you just turned migrations on - no other ideas.

    As for why the out-of-sync happened - hard to say for sure - but I'm guessing you had 'two connection strings' as well (or at some level).

    Make sure that you connection string is 'named' the same as your dbcontext - or put connection at your at DbContext directly

    . It is sometimes a problem, as it's not apparent what the EF/CF 'makes' as its default.

    0 讨论(0)
  • 2020-12-22 01:50

    call this method in your startup code to have the database recreated with the new fields:

    public void CheckForDBChanes()
            {
    
                Database.SetInitializer(new DropCreateDatabaseIfModelChanges<Context>());
            }
    
    0 讨论(0)
提交回复
热议问题