On Apr 18, 1:00 am, Piers Warmers <
pi...@wranglers.com.au> wrote:
> > 1. mySQL failed to create the steercms_property table because one of
> > the keys was too long......
>
> I'm a bit perplexed at this issue. I've only had a brief moment to
> look into it, but nothing is leaping out at me. I presume you just
> removed the index declaration from the schema.yml file and preceded?
> I'll keep looking and see what I can find.
That's right. I removed the 'name' column from the following index
definition:
model: [model, model_id, name]
FWIW, it confused the hell out of me too - I had to experiment with
the
generated SQL to be absolutely sure that it was specifically that
definition that caused it. The culprit is that I created the database
with a default character set of 'utf8', and mysql sets aside up to 3
bytes per character in a varchar, so since model, model_id are both
varchar(50) and name is varchar(255), you end up with a combined
maximum
key-length of 1065. The mysql manual says:
> Prefix lengths are storage engine-dependent (for example, a prefix can
> be up to 1000 bytes long for MyISAM tables, 767 bytes for InnoDB tables).
> Note that prefix limits are measured in bytes, whereas the prefix length
> in CREATE INDEX statements is interpreted as number of characters for
> non-binary data types (CHAR, VARCHAR, TEXT). Take this into account when
> specifying a prefix length for a column that uses a multi-byte character
> set. For example, utf8 columns require up to three index bytes per
> character.
So, possible solutions:
1. Making model_id an integer would take 150 chars off the maximum
key
length, but I don't know enough about steerCMS to know whether
there's
a reason it's a varchar.
2. Setting a single-byte character set for the columns if you know
they'll never need non-ascii characters
3. Only index the first N characters of the name column. Generally
speaking unless the values put into the name column have very
similar
beginnings, you won't need to index the whole column.
4. Tell me off for using utf8 ;)