-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple DbContext Demands (Redundant?) Migration Parameter #5996
Comments
Migrations works by migrating the model/schema associated with a given context. At this stage we don't really have support for models that overlap between contexts - though we do have #2725 on the backlog to improve this. |
Someone just pointed out that you had said A & B belong to Context 1 and C belongs to Context 2. If this is the case, then changes to C should not get included in migrations for Context 1. However, if there are navigation properties between A/B & C then C is actually part of the model for Context 1, even if it doesn't have a DbSet property exposed. You could exclude C from the model in Context 1 if it's not supposed to be part of the model https://docs.efproject.net/en/latest/modeling/included-types.html. |
Thanks, but just to be clear, my models don't actually overlap. At least, I'm pretty sure they don't. I would have expected that any models associated with a context would be migrated in isolation. However my observation is different. Despite specifying the context, models from the other context are migrated also. However, as you also point out there could be other properties at work... |
Any chance you could share the model? Your expectation is correct. |
@rowanmiller I apologize for the delay in answering. The code in question is proprietary and I'm reluctant to publish or share it. I realize this is not useful to you. I feel like I should offer to mock up a code base and attempt to re-create the issue, but I have some current time constraints. So perhaps for now this issue is just in the early information-gathering stage and you may later be able to corroborate and/or re-create. In the meantime, this issue is not a showstopper and you may feel free to close the ticket or do as you think best. Many thanks to you and the team for the work you do. |
@robbpriestley I've done some testing around two separate models in the same project and they did not interfere with each others migrations. My speculation is that there is something joining the classes from each model, so that all the entities are ending up in both models, but of course that is just a guess from limited information. I am going to close this out as I don't think there is anything actionable from our side, but if you do end up with time to distill something that can be shared then just comment and we will re-open. BTW you could use |
@rowanmiller you were completely right. I'm very sorry for wasting your time. But not completely because meanwhile I learned something important. It turned out I was referencing a model entity in both of the contexts!! My bad but I am so happy to have this figured out, thanks!! |
I had problem of EF core Migrations, when I tried to apply migrations for one Context ( i.e. In My Project I have more than one Context), then other Context also included in the Migration and prevented with error for Primary of the Models included in another Context. Not included in the Current Context (Migration to be Applied). The real bug was foreign key relation to one Entity of the other Context was in one of the Entity of the Migration to be applied Context. When I remove the relation then the error gone and the migrations completed. |
Steps to reproduce
dotnet ef migrations add initial
The issue
Error message:
Discussion: While I can understand the conceptual logic for this, specifying one context or the other doesn't actually restrict the migration to only those models associated with the specified context. Thus the need to specify context seems redundant and unnecessary.
Example: If models A and B are associated with context 1 and model C is associated with context 2 and I create a migration and specify context 1, model C is migrated regardless. This either seems like a bug, a logical inconsistency with the design, or is based on presumptions which I am unaware of.
Further technical details
EF Core version: 1.0.0-rc2-final
Operating system: OSX El Cap
Visual Studio version: VS Code 1.2.1
Database: Postgres
"Npgsql": "3.1.2",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.0-rc2-release1"
The text was updated successfully, but these errors were encountered: