Invalid object name 'dbo.EdmMetadata' and 'dbo.__MigrationHistory'

后端 未结 3 859
萌比男神i
萌比男神i 2021-01-01 10:16

I am using Entity Framework 5 and doing a simple query to get a few users from a table.

The SQL database is already created so I use my entities as a way to map what

相关标签:
3条回答
  • 2021-01-01 10:44

    Since the database is already there you will not have dbo.EdmMetadata and dbo.__MigrationHistory which codefirst is expecting. And to resolve this you can try to set the SetInitializer to null.

     static NameOfYourContext()
     {
       Database.SetInitializer<NameOfYourContext>(null);        
     }      
    

    You can see this in the comments section of the this post by Scott Gu

    0 讨论(0)
  • 2021-01-01 10:49

    There are 3 steps you need to follow:

    1- Enable migrations in package manager if you haven't done yet:

    Enable-Migrations
    

    2- Add a migration and make sure to use the -IgnoreChanges switch as you already have an existing database:

    Add-Migration InitialModel -IgnoreChanges
    

    3- Update the database. This will automatically create __MigrationHistory table for you.

    Update-Database
    
    0 讨论(0)
  • 2021-01-01 10:55

    I disabled my exception setting. and it overlooked this exception and went on to create these tables for me automatically

    0 讨论(0)
提交回复
热议问题