Bug #18735
closedIncompatibility with MySQL commands: Add Primary Key table as 1 command
0%
Description
Hello,
I must start off with sayint I'm n00b to typo3.
However, I had a bug where whenever I changed a template, the first time I would look at the corresponding page I'd get an error about not being able to update:
------------------------------
caller t3lib_DB::exec_UPDATEquery
ERROR Unknown column 'SYS_LASTCHANGED' in 'field list'
lastBuiltQuery UPDATE pages
SET
SYS_LASTCHANGED='1209332683'
WHERE
uid=4
debug_backtrace require#14154 // tslib_fe->generatePage_postProcessing#14154 // tslib_fe->setSysLastChanged#14154 // t3lib_DB->exec_UPDATEquery#14154 // t3lib_DB->debug#14154
Warning: Cannot modify header information - headers already sent by (output started at /var/www/localhost/htdocs/typo3/t3lib/class.t3lib_db.php:1137) in /var/www/localhost/htdocs/typo3/typo3/sysext/cms/tslib/class.tslib_fe.php on line 3219
----------------------
When looking in the Install tool > Database -> Compare, these commands were available under ADD Fields:
----------------------
Add fields
1 ALTER TABLE tt_news ADD uid int(11) NOT NULL auto_increment;
1 ALTER TABLE tt_news ADD PRIMARY KEY (uid);
1 ALTER TABLE tx_veguestbook_entries ADD uid int(11) unsigned NOT NULL auto_increment;
1 ALTER TABLE tx_veguestbook_entries ADD PRIMARY KEY (uid);
-----------------------
Executing this gave errors like
-----------------------
caller t3lib_DB::admin_query
ERROR Incorrect table definition; there can be only one auto column and it must be defined as a key
lastBuiltQuery ALTER TABLE tt_news ADD uid int(11) NOT NULL auto_increment;
debug_backtrace require#14154 // tx_install->init#14154 // tx_install->checkTheDatabase#14154 // t3lib_install->performUpdateQueries#14154 // t3lib_DB->admin_query#14154 // t3lib_DB->debug#14154
-----------------------
Also, doing this manually in MySQL gives this error:
-----------------------
mysql> ALTER TABLE tt_news ADD uid int(11) NOT NULL auto_increment;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
-----------------------
Appearently, you can not first add this column as a "normal autoincrement column", then adding a primary key.
Manually doing the following commands in MySQL worked:
-----------------------
mysql> ALTER TABLE tt_news ADD uid int(11) KEY NOT NULL auto_increment;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> ALTER TABLE tx_veguestbook_entries ADD uid int(11) unsigned KEY NOT NULL auto_increment;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
-----------------------
As this happens with a table for both tt_news and tx_vguestbook_entries, I think this is a bug in the typo3 core, not in both the extensions, however I might be wrong.
I have a fairly fresh typo3 installation, 4.2.0, with templavoila, tt_news, ve_guestbook and timtab installed.
My SQL engine is mysql Ver 14.12 Distrib 5.0.44, for pc-linux-gnu (i686) using readline 5.2
and this is running on Gentoo Linux.
tijmen@marie /var/www/localhost/htdocs/typo3 $ php --version
PHP 5.2.6RC4-pl0-gentoo (cli) (built: Apr 23 2008 21:44:53)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
tijmen@marie /var/www/localhost/htdocs/typo3 $ mysql --version
mysql Ver 14.12 Distrib 5.0.44, for pc-linux-gnu (i686) using readline 5.2
(issue imported from #M8309)
Updated by Dmitry Dulepov over 16 years ago
Your database is not up to date.
Go to Install tool, Database Analyzer, and use COMPARE.
Updated by Tijmen Stam over 16 years ago
Currently, this instance of the problem is solved by manually editing the database and does no longer show up in COMPARE.
However, the main issue is that, with my current mysql, you CAN NOT first alter/create an auto_increment column, THEN alter it to be primary key.
You MUST do that in ONE command.
Or, to put it differently, the database being not up to date was not the problem, the fact that typo3 couldn't update the db (and I had to edit it manually) was the problem.
Updated by Christian Kuhn over 15 years ago
Resolved, no change required.
The actual syntax of first adding an auto-increment field and next adding the primary key is technically ok. I don't think this is a TYPO3 problem. For now I set this issue to resolved, no change required. Please reopen if this still happens for you with current mysql versions.