Skip to content

Migration tries to create xmin system column #3854

@0xfelaback

Description

@0xfelaback

BUG: Migration tries to create xmin system column

ISSUE
When configuring optimistic concurrency by mapping a uint property to PostgreSQL’s xmin/xid, the migration generator incorrectly emits an AddColumn for xmin.

Applying the migration fails with:
column "xmin" conflicts with a system column name

Attempting to work around this by removing the generated defaultValue: 0u does not resolve the issue. Instead, EF Core then fails with:
23502: column "<column_name>" contains null values

This creates a deadlock:

  • Keeping the default → conflicts with system column (xmin)
  • Removing the default → violates NOT NULL constraint on existing rows

In environments where generated migrations cannot be modified manually, this blocks deployment entirely.

Repro

  1. Entity:
public class Account
{
    public int account_id { get; set; }
    public uint Version { get; set; }
}
  1. Config:
builder.Property(a => a.Version).IsRowVersion()
       .HasColumnName("xmin")
       .HasColumnType("xid")
       .ValueGeneratedOnAddOrUpdate()
       .IsConcurrencyToken();
  1. Run:
dotnet ef migrations add AddConcurrency
  1. Generated migration includes:
migrationBuilder.AddColumn<uint>(
    name: "xmin",
    table: "Accounts",
    type: "xid",rowVersion: true,
    nullable: false,
    defaultValue: 0u);
  1. Removing defaultValue results in:
23502: column "<column_name>" contains null values
  1. Applying migration fails in all cases

EXPECTED
The provider should recognize mappings to PostgreSQL system columns (xmin/xid) and suppress any physical DDL (e.g., AddColumn) for them.

ENVIRONMENT

  • PostgreSQL: PostgreSQL16
  • Npgsql.EntityFrameworkCore.PostgreSQL: 10.0.1
  • .NET: 10.0.201

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions