Comments (7)
I believe you need to set the options
key/value passed to create_table
so that it has ROW_FORMAT=DYNAMIC
in it.
e.g. (haven't tested this, but):
class CreateStringTranslations < ActiveRecord::Migration[5.1]
def change
create_table :mobility_string_translations, options: "... ROW_FORMAT=DYNAMIC" do |t|
t.string :locale, limit: 15 # NEW limit option
t.string :key, limit: 243 # NEW limit option
t.string :value
t.integer :translatable_id
t.string :translatable_type
t.timestamps
end
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :locale, :key], unique: true, name: :index_mobility_string_translations_on_keys
add_index :mobility_string_translations, [:translatable_id, :translatable_type, :key], name: :index_mobility_string_translations_on_translatable_attribute
add_index :mobility_string_translations, [:translatable_type, :key, :value, :locale], name: :index_mobility_string_translations_on_query_keys
end
end
where ...
would be stuff like COLLATE
, etc. Also note that the code above is a bit outdated, the latest version of Mobility creates the table slightly differently (but same idea, just add the ROW_FORMAT
option).
Btw, looks like this will become the default in Rails 6, since many people have problems with it: rails/rails#34742
from mobility.
Thanks for the report, yes I do know utf8mb4 and use it in production (not with Mobility however). Limiting the length of locale
might make sense, but what is the justifiction for limiting the key
to 243 chars? The key holds the name of the attribute, which is just a string without any constraints, so I don't think a limit should be imposed on that one.
I notice that other translation gems, e.g. Globalize, do not impose a limit on the length of locale, so I'm just a little bit concerned that imposing such a limit may impact some edge cases.
@pwim any thoughts?
By the way, for the problem of long indexes, we use this fix:
# /etc/my.cnf
[mysqld]
innodb_file_format=barracuda
innodb_large_prefix = 1
Not sure if that helps for your case though.
from mobility.
I'd be hesitant to set key lengths just so the migration works with some specific mysql configuration, as we'd be making it work in this case, but potentially creating other edge cases.
As for limiting the locale, Rails by default uses iso639-1 to represent locales as two characters. However, it doesn't actually do anything to enforce it. Having a locale + country code might be the most common alternate pattern (such as "en-CA"). Its also possible that people are using other arbitrary strings (there's nothing stopping you from having "English" as your locale).
One option would be for people running into this issue to just manually adjust the migration files themselves. Another would be to use a different backend (I think the table backend for instance shouldn't have this issue).
from mobility.
One option would be for people running into this issue to just manually adjust the migration files themselves.
Yes, my feeling is that this is quite simple and anyone who cares can do this quite easily. None of the code would change as a result of the limit of the locale
column.
from mobility.
I'm going to close this issue because I don't think we want to change the current auto-generated migrations to support an edge case -- the user can easily do that themselves. We could perhaps add a note to the readme about this, @eiapopeia if you want to make a PR doing that I'd be glad to merge it.
from mobility.
@shioyama I'm sorry to resurrect an issue this old, but how exactly do I modify the migration file so that I don't get this error on mysql 5.5? I've tried limiting the size of the locale and key fields, but no matter how low I go, I still get the same error on mobility_text_translations
.
from mobility.
Thanks for providing that. Using that style of migration and adding the following to the my.cnf makes everything work.
innodb_large_prefix = 1
innodb_file_format = barracuda
innodb_file_per_table = 1
from mobility.
Related Issues (20)
- Any accepted way to store images working with active storage ? HOT 1
- Unique Validation didn't work with locale_accessors on every locales HOT 1
- Not compatible with FastGettext - request for string available locale support HOT 2
- Error when installing on Vitess MySQL db HOT 4
- The presence plugin doesn't work as expected HOT 1
- Destruction of record+translations fails, when model IDs are of the type "varchar(36)" (a UUID string) HOT 3
- accessor super method doesn't work with arguments like class.value(locale: :de) HOT 1
- ordering by specific locale HOT 2
- Add type checking plugin reference HOT 3
- eager_load and pluck builds the wrong query HOT 1
- `i18n` scope incompatible with `exists?` HOT 1
- validates presence: true failing with cache active HOT 3
- Empty content row is created in translation table. HOT 1
- No fixtures are generated / No doc on how to make them ourselves HOT 1
- Not working properly with Rails 7.1.1 HOT 1
- Cannot inject the query when using query method block HOT 2
- Allow composite foreign keys HOT 3
- Mobility with active_storage for translatable attachements HOT 1
- 1.3.0.rc1 Can't assign an translated attribute with a column fallback HOT 1
- Fallbacks in runtime HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mobility.