[development] Adding auto-increment to an existing table

nan wich nan_wich at bellsouth.net
Fri Sep 24 20:02:00 UTC 2010


What is the correct order for adding an auto-increment to a table? Obviously 
this is not it:
  db_drop_primary_key($ret, 'client_activity');
  db_add_field($ret, 'client_activity', 'id', array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique row ID.',
        ));
  db_add_primary_key($ret, 'client_activity', 'id');
  db_add_index($ret, 'client_activity', 'tnt', array('timestamp', 'nid', 
'type'));

This gets these errors at update.php:
	* user warning: Incorrect table definition; there can be only one auto column 
and it must be defined as a key query: update_sql /* admin : update_sql */ ALTER 
TABLE client_activity ADD `id` INT auto_increment DEFAULT NULL in 
C:\www\webapps\drupal6\includes\database.mysql-common.inc on line 298.
	* user warning: Unknown column 'id' in 'client_activity' query: update_sql /* 
admin : update_sql */ ALTER TABLE client_activity CHANGE `id` `id` INT NOT NULL 
auto_increment in C:\www\webapps\drupal6\includes\database.mysql-common.inc on 
line 520.
	* warning: Invalid argument supplied for foreach() in 
C:\www\webapps\drupal6\includes\database.mysql-common.inc on line 109.
	* user warning: You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near ')' at 
line 1 query: update_sql /* admin : update_sql */ ALTER TABLE client_activity 
ADD PRIMARY KEY () in C:\www\webapps\drupal6\includes\database.mysql-common.inc 
on line 374.

 
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100924/01e87248/attachment.html 


More information about the development mailing list