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

Database schema: Specified key was too long #221

Closed
wants to merge 1 commit into from
Closed

Database schema: Specified key was too long #221

wants to merge 1 commit into from

Conversation

bytehead
Copy link
Member

During a fresh install on contao/install while creating the tables:

An exception occurred while executing 'CREATE TABLE `tl_files` (
`id` int(10) unsigned NOT NULL auto_increment,
`pid` binary(16) NULL,
`tstamp` int(10) unsigned NOT NULL default '0',
`uuid` binary(16) NULL,
`type` varchar(16) NOT NULL default '',
`path` varchar(1022) NOT NULL default '',
`extension` varchar(16) NOT NULL default '',
`hash` varchar(32) NOT NULL default '',
`found` char(1) NOT NULL default '1',
`name` varchar(255) NOT NULL default '',
`importantPartX` int(10) NOT NULL default '0',
`importantPartY` int(10) NOT NULL default '0',
`importantPartWidth` int(10) NOT NULL default '0',
`importantPartHeight` int(10) NOT NULL default '0',
`meta` blob NULL,
PRIMARY KEY (`id`),
KEY `pid` (`pid`),
UNIQUE KEY `uuid` (`uuid`),
KEY `path` (`path`),
KEY `extension` (`extension`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;':

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes

It would acutally work with varchar(333) - max key length = 1000 bytes, UTF-8 character uses 3 bytes, so max length of the varchar is 333 (see 5fbe4a9).

What's the reason to use varchar(1022) for the field path ?

@leofeyer
Copy link
Member

We need the field to be longer than 255 characters. And we still want to set a btree index, because in most of the cases, the paths will be shorter than 333 characters.

The discussion is here: contao/core#5556

@leofeyer leofeyer added the bug label Apr 17, 2015
@leofeyer leofeyer added this to the 4.0.0 milestone Apr 17, 2015
@leofeyer leofeyer self-assigned this Apr 17, 2015
@leofeyer
Copy link
Member

I just tried to reproduce the issue, but the tables were all created without problems. Which MySQL version are you running?

@bytehead
Copy link
Member Author

5.6.12

@bytehead
Copy link
Member Author

I will give another shot as well (with newest develop).

@leofeyer
Copy link
Member

Are you using InnoDB? It seems you can fix it by changing the innodb_large_prefix setting.

@bytehead
Copy link
Member Author

Using MyISAM, charset utf8, collation utf8_general_ci

@bytehead
Copy link
Member Author

And still getting the exception on a fresh created database.

@leofeyer
Copy link
Member

No idea. Are you running MySQL in strict mode?

@bytehead
Copy link
Member Author

That's a good question! It actually looks like that:

mysql> SELECT @@GLOBAL.sql_mode;;
+--------------------------------------------+
| @@GLOBAL.sql_mode                          |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0,00 sec)

@bytehead
Copy link
Member Author

Disabling strict mode works. But isn't strict mode a default setting?

@leofeyer
Copy link
Member

Yes, we are trying to maintain strict mode compatibility.

@leofeyer
Copy link
Member

Fixed in 84f7029. Will have to back port this to Contao 3.5.

@bytehead
Copy link
Member Author

Nice, thanks!

@bytehead bytehead deleted the fix-sql-definition branch April 20, 2015 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants