entity framework - ef core: There is already an object named in the database -


hi working on aspnet core app, using ef core version :

"microsoft.entityframeworkcore.design": "1.1.0", "microsoft.entityframeworkcore.sqlserver": "1.1.0"

and dotnet standard 1.6.1.

here scenaro:

  1. 4 dbcontext database
  2. dbset or anyother may shows in 2 or 3 contexts, example acontext contains tablea, bcontext contains tablea. none of them include tables want specific context focus on purpose.
  3. many foreigne keys between tables

this causes dup table in database, resolve this, have done below

  1. create migrationdbcontext include dbset
  2. add migration on migrationdbcontext

here get

  1. successfully create database , tables right schema , name
  2. error when call : servicescope.serviceprovider.getservice().database.migrate(); error message: there object 'a' named in database.

unfortunitly, update-database command in ef core -v not show sql script, script-migration shows simple create sql statement.

my questions are

  1. how debug such of situation?
  2. checked migration file, there have down , method, error seems ef core call method in migration file without calling down first, , result dup table still there. so, there switch control migration behavior?

the simplest way create 1 dbcontext include sets of entities , relations between them. after can separate storage logic repositories. hard way create context-specific migrations each context. , if need add set of entities, exists in context - need create empty migration context. little bit dirty way.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -