Bug #81179 missing length specifier for binary in resulting sql code
Submitted: 22 Apr 2016 15:39 Modified: 30 Jul 17:02
Reporter: Tobias Krämer Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: BINARY, Code First, entity framework, migration, missing length

[22 Apr 2016 15:39] Tobias Krämer
.Net Connectors: 6.9.8
.Net Entity Framework: 6.1.3
language: C#

update-database -script results in binary (without a length parameter) and also update-database to create a new database on MySql results in a field binary(1)

expected beahvior: create binary(10)

error: It seems as if the MaxLength attribute is not used

1. POCO:

public class User
        public int Id { get; set; }

        [Required, MaxLength(10)]
        [Column("Password", TypeName = "binary")]
        public byte[] Password { get; set; }

2. using add-migration in package manager gives me the migration class

                c => new
                        Id = c.Int(nullable: false, identity: true),
                        Password = c.Binary(nullable: false, maxLength: 10, fixedLength: true, storeType: "binary"),
                .PrimaryKey(t => t.Id);

3. update-database -script returns

create table `Users` (`Id` int not null  auto_increment,`Password` binary not null, primary key ( `Id`) ) engine=InnoDb auto_increment=0

I expected:
create table `Users` (`Id` int not null  auto_increment,`Password` binary(10) not null, primary key ( `Id`) ) engine=InnoDb auto_increment=0

How to repeat:
create a new project and add code first entity with the above mentioned class and a context including this class e.g.:

    public class MySqlContext : DbContext
        static MySqlContext()
        public MySqlContext()
            : base("Name=MySqlContext")

        public MySqlContext(string connectionString)
            : base(connectionString)

        public DbSet<User> Users { get; set; }

run enable-migrations
added in configuration.cs:
 SetSqlGenerator("MySql.Data.MySqlClient.EF6", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
run add-migration in package manager (I'm using Visual Studio)
run update-database -script (to see the sql code)
run update-database (to verify this error on the database)

Suggested fix:
my first guess: as in https://dev.mysql.com/doc/relnotes/connector-net/en/connector-net-news-6-5-5.html this was a bug for: Missing length specifier for data types, such as VARBINARY instead of VARBINARY(n).
[25 Apr 2016 6:21] Chiranjeevi Battula
Hello Tobias Krämer,

Thank you for your report and test case.
Verified this behavior on Visual Studio 2013 (C#.Net) with  MySQL Connector/Net 6.9.8.

[25 Apr 2016 6:22] Chiranjeevi Battula

Attachment: 81179.JPG (image/jpeg, text), 285.38 KiB.

[30 Jul 17:02] Christine Cole
Posted by developer:
Fixed as of the upcoming MySQL Connector/NET 8.0.22 release, and here's the proposed changelog entry from the documentation team:

Entity Framework code-first migration excluded the length specifier in the
resulting binary columns.

Thank you for the bug report.