#8197 closed defect (fixed)
cache.py problems with mysql
Reported by: | mrbrush | Owned by: | Remy Blank |
---|---|---|---|
Priority: | high | Milestone: | 0.12 |
Component: | general | Version: | 0.12dev |
Severity: | blocker | Keywords: | mysql cache key reserved word |
Cc: | 20090408@… | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
MySQL considers the word KEY a reserved word, the cache engine creates exceptions when trac is run with MySQL because 'key' is used as a column identifier in the 'cache' table.
Solution: either quote the column name 'key' with ` (backticks), or rename the column to another name which is not a reserved word in MySQL.
Attachments (1)
Change History (13)
by , 16 years ago
Attachment: | cache.py.patch added |
---|
comment:1 by , 16 years ago
Cc: | added |
---|
comment:2 by , 16 years ago
I don't know whether other DB engines will handle the column identifiers quoted with backticks, so the patch might not be portable to other DB engines. Please check it before committing to SVN.
follow-ups: 4 5 comment:3 by , 16 years ago
Oh, great, this had to happen. There are so many reserved words in SQL… And MySQL enforces them all.
Christian, what is the best course of action here? A quick rename of the key
column to id
before anybody using trunk updates? Another database upgrade? Use the backticks (is this even standard SQL)?
comment:4 by , 16 years ago
I've tried the patched version with the SQLite database and it works. I don't know about other databases though.
comment:5 by , 16 years ago
Replying to rblank:
A quick rename of the
key
column toid
before anybody using trunk updates?
…along with a procedure for fixing the breakage for those who had already upgraded:
- Change
db_version
back to 21 - Drop the
cache
table - Upgrade again
follow-up: 7 comment:6 by , 16 years ago
The backticks don't seem to work with PostgreSQL. This is highly annoying, if we create another db23.py then we will have again merge trouble in the MultiRepos branch.
So yes, I agree with your proposal, simply change key → id, and document how to recover manually, which can be a simple sql script (so that it will also work on the MultiRepos branch):
DROP TABLE cache; CREATE TABLE cache ( id text PRIMARY KEY, generation int );
By the way, it looks like generation
was text
so far… another detail to fix in db22.py at the same time?
comment:7 by , 16 years ago
Replying to cboos:
So yes, I agree with your proposal, simply change key → id, and document how to recover manually,
Ok, will do ASAP.
By the way, it looks like
generation
wastext
so far… another detail to fix in db22.py at the same time?
Oops, er, yes, right…
comment:8 by , 16 years ago
Ok, so after a rename, an environment that has already been upgraded generates the following error:
OperationalError: no such column: id
I hope this is enough for people searching for that error to find this ticket. Patch coming up shortly.
comment:9 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Both issues are fixed in [8079] and merged to the multirepos branch in [8081].
For people who get the error above, please follow the instructions in [8079] if you are using trunk, or those in [8081] if you are using the multirepos branch.
mrbrush: Thanks for the bug report!
comment:10 by , 16 years ago
Owner: | set to |
---|
comment:11 by , 16 years ago
You are very welcome.
As a final note I would like to add that the recovery script does not work for MySQL as it cannot handle primary key columns with unlimited key length, as would come for the id column with column type TEXT. The error message is:
ERROR 1170 (42000): BLOB/TEXT column 'id' used in key specification without a key length
Instead, one can use the following script to do the recovery with MySQL:
DROP TABLE IF EXISTS cache; CREATE TABLE cache ( id text, generation int, PRIMARY KEY (id(333)) );
comment:12 by , 16 years ago
Thanks for the update. The MySQL connector seems to limit the key length for a signle column to 255 characters, so if the script above doesn't work, try:
DROP TABLE IF EXISTS cache; CREATE TABLE cache ( id text, generation int, PRIMARY KEY ( id(255)) );
Patch fixing the problem by quoting every usage of 'key' as a column identifier.