[development] Adding auto-increment to an existing table

nan wich nan_wich at bellsouth.net
Fri Sep 24 23:51:32 UTC 2010


Thanks, I'll look at your idea. As a very remote option, I don't think any of 
the data is critical yet, so I may be able to find a slow time and just 
uninstall the module and re-install it.

And, no it doesn't need to run on Postgres, but I thought these new functions 
for 6.x were supposed to work with both.
 
Nancy
Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr.




________________________________
From: Sascha Grossenbacher <saschagros at gmail.com>
To: development at drupal.org
Sent: Fri, September 24, 2010 4:29:24 PM
Subject: Re: [development] Adding auto-increment to an existing table

Hi

On Fri, Sep 24, 2010 at 10:02 PM, nan wich <nan_wich at bellsouth.net> wrote:
> 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.

Try using the $new_keys argument of db_change_field() to create the
primary key at the same time. If that doesn't work either (possible if
it does it in a separate query), then do not remove the primary key
before making the field autoincrement.

Also, if you need to do that and this code needs to run on PostgreSQL
too, then you need to make it conditional and only remove/re-add the
key for PostgreSQL.

Sascha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20100924/49cfd75d/attachment.html 


More information about the development mailing list