Pomelo.EntityFrameworkCore.MySql error with EF Core 3.0

0

I am trying to connect to MySQL database using Pomelo.EntityFrameworkCore.MySql and EF Core 3.0

I have followed the guide provided by Pomelo.

When I run the web application, I can see some tables getting created successfully. However, tables with GUID as ID are getting the following error:

An error occured during migration
MySql.Data.MySqlClient.MySqlException (0x80004005): BLOB/TEXT column 'Id' used in key specification without a key length

How to fix this? how to use GUID as an ID in MySql and how to workaround this error?

mysql
entity-framework-core
asked on Stack Overflow Nov 12, 2019 by Yousi

1 Answer

0

I found a solution, not sure if it is a workaround or is this the normal way to do it though.

Just add the below in your DataContext class:

protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.Entity<AppUser>(entity => entity.Property(m => m.Id).HasMaxLength(255));
        }

Also, if you're moving from another database engine to MySQL, better to remove all your migrations and create new ones so it will implement the above code and use Pomelo to create the migrations properly for MySQL

I hope this is helpful to anyone who is stuck as I was

answered on Stack Overflow Nov 12, 2019 by Yousi

User contributions licensed under CC BY-SA 3.0