-
Notifications
You must be signed in to change notification settings - Fork 228
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
Migration dropping wrong objects on down #3057
Comments
@RichardBurns1982 thanks for filing. This looks like it wouldn't be a PG-specific bug - if it's possible for you to try this out on SQL Server/SQLite, that would be really helpful (if so, then it belongs on the main EF repo and not here). Otherwise, it probably will take me a while before I can investigate. |
@roji I just got the same behavior on SQL Server! I have 3 Entities with the same name "Assessment" in different namespaces and schemas that have some common names for columns
I just created the migration for VendorAssessment and at the migrationBuilder.CreateTable(
name: "Assessments",
schema: "vendor",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AssessmentTypeId = table.Column<int>(type: "int", nullable: false),
PartitionId = table.Column<int>(type: "int", nullable: true),
Status = table.Column<int>(type: "int", nullable: false),
IncludeProviderRiskAssessment = table.Column<bool>(type: "bit", nullable: false),
AssociateId = table.Column<int>(type: "int", nullable: true),
MasterPlanId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Assessments", x => x.Id);
table.ForeignKey(
name: "FK_Assessments_AssessmentTypes_AssessmentTypeId",
column: x => x.AssessmentTypeId,
principalSchema: "vendor",
principalTable: "AssessmentTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Assessments_Associates_AssociateId",
column: x => x.AssociateId,
principalSchema: "bc",
principalTable: "Associates",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Assessments_MasterPlans_MasterPlanId",
column: x => x.MasterPlanId,
principalTable: "MasterPlans",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Assessments_Partitions_PartitionId",
column: x => x.PartitionId,
principalSchema: "bc",
principalTable: "Partitions",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}); while at the migrationBuilder.DropForeignKey(
name: "FK_Assessments_MasterPlans_MasterPlanId",
schema: "isra",
table: "Assessments");
migrationBuilder.DropForeignKey(
name: "FK_Assessments_Partitions_PartitionId",
schema: "tra",
table: "Assessments"); You can see that the schemas for the down are completely different. The same happened for the migration of TRA.Assessment, just didn't notice because I didn't revert the migration. If you want I can create a small project and try to replicate exactly that. |
I opened an issue at the EF repo for this |
Closing here as this seems to be an EF-side thing. |
Duplicate of dotnet/efcore#35358 |
We have two objects with the same name in different namespaces and schemas in the database:
The ConsoleAppEfSandbox.Entities.Organizations.DataSet object was added after the ConsoleAppEfSandbox.Entities.Dts.DataSet object. Both objects have the same relationship to a user and so EF generates the same foreign key name, which is fine as they are in different schemas.
The first migration creates the users table and dts.data_sets objects:
The second migration, once the organizations.data_sets object is configured generates an incorrect migration. As the below shows the Up is fine, but the down tries to drop the foreign key from the wrong schema:
As you can see, on the down it tries to drop FK_data_sets_User_CreatedByUserId from dts schema and not organizations as the up has created.
I have uploaded a sample console app which demonstrates this: https://github.com/RichardBurns1982/npgsql-ef-migration-issues-1
The text was updated successfully, but these errors were encountered: