Skip to content
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

When running the alchemy scaffold on MySQL, an error is generated on table creation #1049

Merged
merged 1 commit into from Aug 10, 2013

Commits on Jul 18, 2013

  1. When running the alchemy scaffold on MySQL an error is generated on t…

    …able
    
    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.
    Chris Davies committed Jul 18, 2013
    Copy the full SHA
    8320674 View commit details
    Browse the repository at this point in the history