Entity Framework migration for ASP.Net Core Identity creates key without key length

0

Using ASP.NET Core Identity and Entity Framework Core 5.0 (EF Tools also 5.0.0), the migration code generated created key (for tables like ApplicationUser, from IdentityUser) with Id and no key length.

Getting an error when running with MySql:

MySqlConnector.MySqlException (0x80004005): BLOB/TEXT column 'Id' used in key specification without a key length

For example:

    modelBuilder.Entity("MyProject.ApplicationUser", b =>
        {
            b.Property<string>("Id")
                .HasColumnType("TEXT");
        }
asp.net
entity-framework
asp.net-core
entity-framework-core
asp.net-core-identity
asked on Stack Overflow Nov 22, 2020 by Jonas Arcangel • edited Nov 22, 2020 by marc_s

1 Answer

0

The issue was that I was using Sqlite as provider during build time. It was generating migration appropriate for Sqlite, and not for MySQL.

Our solution, as we need to cater to Sqlite, MySQL and MS SQL, is to create a DBContext for each provider, and abstract it away to be used by the services.

answered on Stack Overflow Nov 23, 2020 by Jonas Arcangel

User contributions licensed under CC BY-SA 3.0