During the upgrade process to Drupal 6, I noticed that my imagecache presets were broken. I deleted them and tried to create a new one. This resulted in this error:

Field 'presetid' doesn't have a default value query: INSERT INTO imagecache_preset (presetname) VALUES ('logo_klein') in E:\Apache\htdocs\totem_6\includes\common.inc op regel 3324.

I was able to solve this by setting the auto_increment property on the presetid column in the imagecache_preset table, but I'm not sure if this is the real solution or an ugly hack.

CommentFileSizeAuthor
#6 imagecache_333769.patch1.33 KBdrewish
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcvangend’s picture

(Sorry for the error with the < code > tag!)
By the way, I forgot to mention I had to do the same with the actionid column in imagecache_action in order to add actions.

techninja’s picture

Yep, same problem here. Too bad I decided it was my old d5.x presets before noticing/checking the issue queue (And deleting them all). Good call marcvangend!

I can switch up the table, but unfortunately this leaves our less advanced brethren out of the loop (Not to mention, it might very well be a nasty hack, as I recall drupal was supposed to handle auto-increments through the database abstraction layer because of shoddy support for auto-increment in DB systems other than mysql)

Suggestions anyone?

yhahn’s picture

Status: Active » Needs review

You can re-implement the primary keys (which will receive the auto increment property) with the following snippet in imagecache.install using the Schema API.

<?php
imagecache_update_5() {
  $ret = array();
  
  // Rebuild the primary key to enable auto-increment
  $schema = imagecache_schema();

  db_drop_primary_key($ret, 'imagecache_preset');
  db_change_field($ret, 'imagecache_preset', 'presetid', 'presetid', $schema['imagecache_preset']['fields']['presetid'], array('primary key' => $schema['imagecache_preset']['primary key']));
  
  db_drop_primary_key($ret, 'imagecache_action');
  db_change_field($ret, 'imagecache_action', 'actionid', 'actionid', $schema['imagecache_action']['fields']['actionid'], array('primary key' => $schema['imagecache_action']['primary key']));
  
  return $ret;
}
?>
dopry’s picture

@yhahn: can you post as a patch?

drewish’s picture

Status: Needs review » Needs work

Read the docs for hook_update_N, you can't reference the schema in an update. Think about it for a minute... what happens after you update the schema and someone goes to run this update... assumptions you're making about the schema will no longer be true.

drewish’s picture

Status: Needs work » Needs review
FileSize
1.33 KB

totally untested but here's the correct way to do this.

drewish’s picture

Status: Needs review » Closed (duplicate)