Closed thiagomajesk closed 3 years ago
Yes, the comment in the issue you linked explains it. The issue is not the index name. The issue is that you are indexing data that is longer than the maximum index size. This is a MySQL behaviour, there is nothing Ecto can do. Either change the column or index only part of the data.
I also recommend reading the reply to the comment you quoted in full: https://github.com/elixir-ecto/myxql/issues/102#issuecomment-752053310 - there is no way Ecto can address a limitation that is in your database. Maybe we could silently truncate the data for you, but if silently truncating was a good idea, then MySQL would do it instead of erroring. Instead you should be explicit which part of your data you want to index in the limited size.
I was playing with the idea of migrating a Postgres database to MySQL 8 but the experience hasn't been pleasant so far. After running the migrations (
mix ecto.migrate --log-sql
) I'm having this error:Even if I override the index name to be shorter, the problem still persists:
create unique_index(:locations, [:country, :state, :city, :district], name: "i")
.After searching a little bit on the internet it seems there's no obvious solution, problems vary between changing engine, charset, or collation. There's also this other issue that seems related, but as you can see from the logs, the table columns are already limited by default to 255.
I just did a clean installation of the MySQL package on WSL (
mysql Ver 8.0.25-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
). It seems that the experience out-of-the-box is not as smooth as I thought it would be for Postgres.The @rkorzeniec's fix of setting the
size
opt to 191 does the trick, but what would be a long-term solution for this? It's really counterintuitive and it's the first time I've encountered this problem as well.