Pomelo.EntityFrameworkCore.MySql error with EF Core 3.0

entity-framework-core mysql

Question

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?

1
1
11/12/2019 3:17:42 PM

Accepted Answer

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

1
11/12/2019 4:09:00 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow