Chris Davies
2013-07-18 a302f630ce4e6ef0f9c0975bdf1ff0a883e68b17
refs
author Chris Davies <mcd@daviesinc.com>
Thursday, July 18, 2013 22:38 +0200
committer Chris McDonough <chrism@plope.com>
Friday, August 30, 2013 18:45 +0200
commita302f630ce4e6ef0f9c0975bdf1ff0a883e68b17
tree 72eec9446686c3ecd5d53ab992cf771134b627cb tree | zip | gz
parent ae61353610f947a03055fc0fd07b86f6c4809168 view | diff
When running the alchemy scaffold on MySQL an error is generated on table
creation:

sqlalchemy.exc.OperationalError: (OperationalError) (1170, "BLOB/TEXT column 'name' used in key specification without a key length") '\nCREATE TABLE models (\n\tid INTEGER NOT NULL AUTO_INCREMENT, \n\tname TEXT, \n\tvalue INTEGER, \n\tPRIMARY KEY (id), \n\tUNIQUE (name)\n)\n\n' ()

MySQL (and MariaDB) doesn't allow an index of more than 255 characters. After
modifying the scaffold and creating a project, the following results:

> show create table models;
+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| models | CREATE TABLE `models` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` text,
`value` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `my_index` (`name`(255))
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 |
+--------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

A unique index is created on the name field, constrained to 255 characters.

When run on SQLite3:

sqlite> .schema models
CREATE TABLE models (
id INTEGER NOT NULL,
name TEXT,
value INTEGER,
PRIMARY KEY (id)
);
CREATE UNIQUE INDEX my_index ON models (name);

the mysql specific constraint is ignored and the table is created with a unique
index as desired.
1 files modified
5 ■■■■ changed files
pyramid/scaffolds/alchemy/+package+/models.py 5 ●●●● diff | view | raw | blame | history