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:
- 4 dbcontext database
- 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.
- many foreigne keys between tables
this causes dup table in database, resolve this, have done below
- create migrationdbcontext include dbset
- add migration on migrationdbcontext
here get
- successfully create database , tables right schema , name
- 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
- how debug such of situation?
- 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
Post a Comment