Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Duplicate Column with same name is getting Creating when using Code First Approach (postgres) #10155


User avatar
0
mahendra created
  • What is your product version?
  • 5.2
  • What is your product type (Angular or MVC)?
  • Angular
  • What is product framework type (.net framework or .net core)?
  • .net Core

If issue related with ABP Framework

  • What is ABP Framework version?
  • 5.2

Issue: I am using Code First approach for creating the database. My Database is in postgres as backend and i am using asp.net core for API development. I have modidifed my table as Following Added Following column in the table structure

public virtual int? OEMarketplaceProviderId​ { get; set; }
    [ForeignKey("OEMarketplaceProviderId​​")]
    public virtual OEMarketPlaceProvider OEMarketplaceProviderId​FK { get; set; }
    public virtual string LongDescription​ { get; set; }
    public virtual int? OEEnumNotificationStatus​Id { get; set; }

    [ForeignKey("OEEnumNotificationStatus​Id​")]
    public OEEnumMaster OEEnumNotificationStatus​Fk { get; set; }

    // inplace of OESystemStatusMasterId
    public virtual int? Status { get; set; }
    [ForeignKey("Status​​")]
    public OEEnumMaster StatusFk { get; set; }

Migration Generated

migrationBuilder.AddColumn<int>(
                name: "OEEnumNotificationStatusId",
                table: "OESystem",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "OEEnumNotificationStatus​Id​",
                table: "OESystem",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "OEMarketplaceProviderId",
                table: "OESystem",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "OEMarketplaceProviderId​​",
                table: "OESystem",
                nullable: true);
 

 -

Snapshot Generated

b.HasOne("OneEnterprise.iHUB.OEEnumMasters.OEEnumMaster", "OEEnvironmentMasterFk")
                        .WithMany()
                        .HasForeignKey("OEEnvironmentMasterId");

                    b.HasOne("OneEnterprise.iHUB.OEMarketPlaceProviders.OEMarketPlaceProvider", "OEMarketplaceProviderIdFK")
                        .WithMany()
                        .HasForeignKey("OEMarketplaceProviderId​​");

                    b.HasOne("OneEnterprise.iHUB.OEEnumMasters.OEEnumMaster", "OESystemStatusMasterFk")
                        .WithMany()
                        .HasForeignKey("OESystemStatusMasterId");

                    b.HasOne("OneEnterprise.iHUB.OEEnumMasters.OEEnumMaster", "StatusFk")
                        .WithMany()
                        .HasForeignKey("Status​​");

                    b.HasOne("OneEnterprise.iHUB.SystemSpecification.SystemInfo", "SystemInfoFk")
                        .WithMany()
                        .HasForeignKey("SystemInfoId");

Related Entity

[Required]
        public virtual string Name { get; set; }

        public virtual string Code { get; set; }

        public virtual string Description { get; set; }

        public virtual string NameLanguageId { get; set; }

        public virtual string DescriptionLanguageId { get; set; }

        public virtual string ToolTip { get; set; }

        public virtual string ToolTipLanguageId { get; set; }

        public virtual string HelpId { get; set; }

        public virtual EnumType EnumType { get; set; }

        public virtual bool IsDefault { get; set; }

Entity 2

 public virtual string Description { get; set; }

        public virtual string Address { get; set; }

        public virtual string Phone { get; set; }

        public virtual string Mail { get; set; }

        public virtual string Website { get; set; }

        public virtual int OEBusinessPartnerId { get; set; }

        [ForeignKey("OEBusinessPartnerId")]
        public OEBusinessPartner OEBusinessPartnerFk { get; set; }

        public virtual int? OEEnumMasterBusinessPartnerStatusId { get; set; }

        [ForeignKey("OEEnumMasterBusinessPartnerStatusId")]
        public OEEnumMaster OEEnumMasterBusinessPartnerStatusFk { get; set; }

        public virtual int? OEMarketPlaceOfferId { get; set; }

        [ForeignKey("OEMarketPlaceOfferId")]
        public OEMarketPlaceOffer OEMarketPlaceOfferFk { get; set; }

        public virtual int? OEMarketPlaceRatingId { get; set; }

        [ForeignKey("OEMarketPlaceRatingId")]
        public OEMarketPlaceRating OEMarketPlaceRatingFk { get; set; }

Please suggest what could be the reason and if is Deployed in the Testing environment. How we can fix it. In Snapshot we can easily check that duplicate column has been created in Migration and snapshot, however in entity i have placed the column name only once

thanks Ashish


10 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    I couldn't find any related issue in npgsql GitHub repository. You can try to upgrade npgsql version to latest possible version. Then, you can modify this migration manually to remove the duplicate field generation.

    I think, if you try to apply this migration, it will fail since it will not be able to create the same field twice.

  • User Avatar
    0
    mahendra created

    Hi ismcagdas ,

    Still Column with same column is Created, we are not getting any issue. I think remove column from the migration is not a good idea.

    Thanks Ashish

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @mahendra

    If you can share your project via email with [email protected], we can try to take a deeper look but I'm not sure if we can find another solution or not.

    Thanks,

  • User Avatar
    0
    mahendra created

    HI ismcagdas ,

    I am unable to send the attachment in this due to following reason. Please let me know other email address or URL where i can attach the zip. I tried to send the mail from my gmail account as well as office email account. But not able to send the mail.

    Thanks Ashish Mohan

  • User Avatar
    0
    mahendra created

    Hi Expert,

    I have shared the zip in given in your given mail. Looking forward for help from you .

    Thanks Ashish Mohan

  • User Avatar
    0
    mahendra created

    Hi Expert , I have shared the zip in given in the following mailId ([email protected]). Any help will be much appreciated. Waiting for your response.

    Thanks Ashish

  • User Avatar
    0
    mahendra created

    Hi Expert,

    Any update for us. Looking forward to hear from you soon. We are stuck due to this issue.

    Thanks Ashish

  • User Avatar
    0
    musa.demir created

    The source of the error you mentioned is migrations. I removed your migrations and generate a fresh one. It all worked. I did research within migrations but could not see the exact source of the error.

  • User Avatar
    0
    mahendra created

    Hi musa.demir,

    Thanks for your response.

    **Have you removed all the migration and generated the new Migration ? **

    Note : We are facing this issue only for the foregin key column. I tried again and facing same issue.

    Table Class where added the column OEEnumNotificationStatusId

    [Table("OESolutionProcessLink")]
    public class OESolutionProcessLink : Entity
    {
    
        public virtual int OESolutionId { get; set; }
    
        [ForeignKey("OESolutionId")]
        public OESolution OESolutionFk { get; set; }
    
        public virtual int OEProcessId { get; set; }
    
        [ForeignKey("OEProcessId")]
        public OEProcess OEProcessFk { get; set; }
    
        public virtual int? OEEnumNotificationStatus​Id { get; set; }
    
        [ForeignKey("OEEnumNotificationStatus​Id​")]
        public OEEnumMaster OEEnumNotificationStatus​Fk { get; set; } 
    
    }
    

    Following Migration is Generated When i Change the Encoding to ANSI, i noticed that there are some special characters in the migration for the column OEEnumNotificationStatusId namespace OneEnterprise.iHUB.Migrations { public partial class addedIssueColumn : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn<int>( name: "OEEnumNotificationStatusId", table: "OESolutionProcessLink", nullable: true);

            migrationBuilder.AddColumn&lt;int&gt;(
                name: "OEEnumNotificationStatus​Id​",
                table: "OESolutionProcessLink",
                nullable: true);
    
            migrationBuilder.CreateIndex(
                name: "IX_OESolutionProcessLink_OEEnumNotificationStatus​Id​",
                table: "OESolutionProcessLink",
                column: "OEEnumNotificationStatus​Id​");
    
            migrationBuilder.AddForeignKey(
                name: "FK_OESolutionProcessLink_OEEnumMaster_OEEnumNotificationStatus~",
                table: "OESolutionProcessLink",
                column: "OEEnumNotificationStatus​Id​",
                principalTable: "OEEnumMaster",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }
    
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_OESolutionProcessLink_OEEnumMaster_OEEnumNotificationStatus~",
                table: "OESolutionProcessLink");
    
            migrationBuilder.DropIndex(
                name: "IX_OESolutionProcessLink_OEEnumNotificationStatus​Id​",
                table: "OESolutionProcessLink");
    
            migrationBuilder.DropColumn(
                name: "OEEnumNotificationStatusId",
                table: "OESolutionProcessLink");
    
            migrationBuilder.DropColumn(
                name: "OEEnumNotificationStatus​Id​",
                table: "OESolutionProcessLink");
        }
    }
    

    }

  • User Avatar
    0
    musa.demir created

    Hi @mahendra Yes, I have removed all migrations and created a fresh one. That also solved the problem. You can also check https://support.aspnetzero.com/QA/Questions/10155/Duplicate-Column-with-same-name-is-getting-Creating-when-using-Code-First-Approach-postgres#answer-5eac3cfb-5f57-c467-8e2b-39fb32833e3b. The problem seems to be in npgsql.