Skip to content

HasCheckConstraint does not work with columns starting with uppercase #1727

Closed

Description

@rajmondburgaj

I am trying to run a migration where I use HasCheckConstraint method on one entity. For some reason it complains like the column is not there, but the column is present in the entity. I think somehow the column name is changed to lowercase and maybe is not able to find it the table, therefore throwing.

modelBuilder.Entity<FeatureDbEntity>(entity =>
{
      ...
      entity.HasKey(x => x.Id);
      entity.HasCheckConstraint("CK_Features_Version", "Version > 0");
      ....
}

image

Activity

  1. roji commented on Feb 23, 2021

    @roji
    Member

    You need to quote the column name Version in the check constraint SQL - PostgreSQL folds unquoted identifiers to lower-case, which is why it's complaining about lower-case version not being found:

    entity.HasCheckConstraint("CK_Features_Version", @"""Version"" > 0");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions