I’m following Bobs tutorial on creating custom DB tables. I’ve copied the schema and created the chunk and resource. When I browse the resource and submit the form I get:
Create Quotation Classes
Generating class and map files
Saving schema
Old class and map files removed
Schema parsed
createObjectContainer() failed
The error log shows:
(
[0] => 42000
[1] => 1170
[2] => BLOB/TEXT column ‘quote’ used in key specification without a key length
)
Research tells me this is a common error for mysql with this field/index type but I can’t find how to define the index length in the schema.
I’ve tried adding a value length to the schema but still get the same error
It was a machine I set up myself - being a novice I could have done anything.
It’s not a big issue, Modx is running okay and I seem to be getting on okay so please don’t waste your time with it.
Thanks Bob for making the change. However, additionally it’s also necessary to add an appropriate value to the “length” attribute in the <column> element of the <index> for “quote”. E.g.:
I did not look at the other schemas in ClassExtender. But generally a change is only necessary, if the schema has <index> elements with additional information (for the parser/table generator).
As an example: If you have a schema like this (<model ... version="1.0">), it won’t work.
index="index" tells the code to create an index for the column “name”, but the field size (precision="200") is too big for the index. For “InnoDB”, the maximun index length is 767 bytes, which gives you a maximum of 191 characters for a 4-byte character set (utf8mb4).
So to give the index a different length from the field, you have to add an <index> element to the schema, and change the model-version to “1.1”, so that the <index> element gets processed:
When the length is not defined in the <index> element, the complete content of the column is used for the index. In this case the column context_key has a length of only 100 (<field key="context_key" dbtype="varchar" precision="100" ...), so the maximum index size will never be exceeded.
Here a fulltext index is used (type="FULLTEXT"), which works differently and doesn’t have the same size limit.
I think a fulltext index only makes sense, if you intend to query the table with the specific SQL syntax → MATCH (...) AGAINST (...).
It’s also questionable if you even need an index for this column at all.
However you decide to fix the schema (no index, fulltext index, normal index with limited size), the main thing here is, that the example code in the tutorial should preferably run without throwing an error.
Unfortunately, this schema currently still throws an error when you run the ClassExtender snippet to create the database table in the database.
Here is a (possible example for an) adapted schema, that should work (and also more closely matches the CREATE TABLE ... SQL query in the Database Table First section of the tutorial: