Skip to content
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

Migrations is ignoring my maxlength when columntype was specified #3985

Closed
pedroivobraga opened this issue Dec 5, 2015 · 3 comments
Closed

Comments

@pedroivobraga
Copy link

I'm generating my database using migrations, when I specific the column type as varchar and maxlength the result is varchar(1)

        modelBuilder.Entity<Area>(entity =>
        {
            entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(50)
                .HasColumnType("varchar");
        });

I had to remove the column type to generate right.

@rowanmiller
Copy link
Contributor

This is by-design, if you specify an explicit type then you are overriding all the other hints that EF would give the provider to work out a data type to use. You would typically put "varchar(50)" as the data type if that is what you want.

Leaving open for triage, as it seems a little strange that we are converting "varchar" to "varchar(1)"

@justdmitry
Copy link

As soon as MaxLength attribute (as source for HasMaxLength) is used not only for db schema, but also by GUI generators/validators - it's desirable for HasColumnType() also honor it.

@rowanmiller
Copy link
Contributor

You are fine to put the max length attribute on, but if you use HasColumnType() then you are explicitly telling EF what type to use for the column. EF is not doing anything to convert this to varchar(1), it is just sending exactly what you supplied to the database (and SQL Server decides that varchar means varchar(1)).

BTW if you just want to swap to a non-Unicode data type then we have a work item to bring back IsUnicode so that you don't have to drop down to a hard-coded data type (#3420).

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants