-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using utf8mb4 Specified key was too long; max key length is 767 bytes #651
Comments
Interesting.. I believe UTF-8 is the default for ActiveRecord / rails so I'm guessing this is probably rarely encountered. It seems that 767 bytes is the standard limit for a column using InnoDB. My question is whether the option string you are applying here will only be executed against databases with that setup or whether this could potentially cause errors if attempted to execute against other databases if we added it to the standard migration? |
FWIW, my team ran into related issues. We had a database incorrectly configured with a default charset of latin1 and so the versions table got set to latin1 and we started seeing exceptions in production with some Japanese characters. I'm not sure what the preferred solution should be from the paper_trail standpoint, but at the least, it might be worth bringing up the issue of charsets in the README and perhaps provide some options for passing through your desired charset. |
Default database character sets
Solution
Makes sense to me, but Ben makes a good point:
Unfortunately, no. We can't simply copy the given solution into our migration template ( create table derp () DEFAULT CHARSET=utf8;
-- ERROR: syntax error at or near "DEFAULT" So, we'll have to have some conditional logic. Maybe something like: def options
if ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
'ROW_FORMAT=DYNAMIC ENGINE=InnoDB DEFAULT CHARSET=utf8'
else
''
end
end I've never had to write something like the above, so I have no idea if it's the best implementation. |
I am still seeing this bug (using 5.0.1), wasn't using |
Hi Ian. You're seeing the "Specified key was too long; max key length is 767 bytes" in 5.0.1? When do you get the error, when you're running the migration that creates the
Possibly? But we must use utf8mb4 because Ruby strings are UTF-8 by default, and utf8mb4 is the only compatible CHARSET in MySQL, right? |
According to this SO answer:
It goes on to say that the maximum length of a utf8mb4 varchar key is 191 chars.
So, assuming we can reproduce this issue, one solution may be to limit |
Yes— specifically the whole output
As for the column type— |
Ian, it all works for me in a new app with rails 5.0.0.rc1, mysql 5.7.12, ruby 2.3.1. What are you using? |
Ian, I haven't heard back from you, so I'm going to close this issue again. If anyone knows how to reproduce Ian's issue, please let us know, thanks! |
I am still have this bug with mariadb 10.1 |
Oh hey! Sorry, missed the notification. Rails 4.2.1 |
Well, it wasn't easy, but I was able to reproduce this on a VM with ubuntu 16.04, rails 4.2.6, mysql 5.6.16, and ruby 2.3.0. Re-opening.
I'm going to try this. |
Seems to work. |
Fix worked for me. Thanks! |
Again, why are we forcing |
Yes, we want PT to have support for emoji (and other 4-byte chars). |
We've run into this and unless you change tables that store user input to utf8mb4, you get exceptions and/or data loss. Phones have a lot of 4byte characters easily accessible on the default keyboards, so users add smiley faces, etc. Since they are a valid part of UTF-8, they are not easy to remove before sticking data into the database. |
I'm using utf8mb4 for my database to support emoji. Not sure if anyone might encounter the same problem illustrated below. This might be a potential issue that should be highlighted in the docs. Perhaps the migrations file should always enforce utf8 for the CHARSET option.
Using:
JRuby 1.7.19 (1.9.3p551)
Rails 4.2.5
Activerecord (4.2.5)
paper_trail (4.0.0)
Error:
Fix:
Note:
Force CHARSET=utf8 on your versions migration created by
rails g paper_trail:install
The text was updated successfully, but these errors were encountered: