0
votes

I have just taken over a Drupal 7.14 website that an old colleague made. I have logged in, but whenever I go to Admin > Content and click 'edit' to edit the content of any of my basic pages I get the following error message:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'source' in 'where clause': SELECT url_alias.* FROM {url_alias} url_alias WHERE (source = :db_condition_placeholder_0) ; Array ( [:db_condition_placeholder_0] => node/1 ) in path_load() (line 419 of /home/sites/mediamatterstechnology.com/public_html/includes/path.inc).

Also if I go into Admin > Configuration > URL Aliases I get a similar message which is shown below:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'language' in 'where clause': SELECT 1 FROM {url_alias} WHERE language <> :language LIMIT 0, 1; Array ( [:language] => und ) in path_admin_overview() (line 18 of /home/sites/mediamatterstechnology.com/public_html/modules/modules/path/path.admin.inc).

I would be so grateful for any help with this. I have been working on it for days, but I am a newbie with Drupal.

screenshot

1

1 Answers

0
votes

Drupal 5 and Drupal 6 don't have one (or two) of those fields. The reason why that database doesn't contain those fields could be:

  • The site was update from Drupal 5 / Drupal 6 to Drupal 7, and the update was not successful
  • The database got corrupted
  • A module removed the fields from the database
  • Those fields were manually removed

What you can do is adding the missing fields to the database, trying to first update the existing fields (in the case the site was updated from a previous Drupal version, and the update was not successful).

The following code should help.

// Drop indexes.
@db_drop_index('url_alias', 'src_language_pid');
@db_drop_unique_key('url_alias', 'dst_language_pid');

// Rename the fields, and increase their length to 255 characters.
@db_change_field('url_alias', 'src', 'source', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
@db_change_field('url_alias', 'dst', 'alias', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));

if (db_field_exists('url_alias', 'language')) {
  $spec = array(
    'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  );
  db_change_field('url_alias', 'language', 'language', $spec);
  db_update('url_alias')
    ->fields(array('language' => LANGUAGE_NONE))
    ->condition('language', '')
    ->execute();
}
else {
  $spec = array(
    'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
    'type' => 'varchar',
    'length' => 12,
    'not null' => TRUE,
    'default' => '',
  );
  db_add_field('url_alias', 'language', $spec);
}

// Add indexes back.
@db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));
@db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));

If this code doesn't get the missing fields, then it was not a failed update. In this case, you can use the following code, which should be used when you are sure the site was not updated from a Drupal version that is earlier than Drupal 7.

// Drop indexes.
@db_drop_index('url_alias', 'src_language_pid');
@db_drop_unique_key('url_alias', 'dst_language_pid');

$spec = array(
  'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
  'type' => 'varchar',
  'length' => 12,
  'not null' => TRUE,
  'default' => '',
);
db_add_field('url_alias', 'language', $spec);

$spec = array(
  'type' => 'varchar',
  'length' => 255,
  'not null' => TRUE,
  'default' => ''
);

db_add_field('url_alias', 'source', $spec);

// Add indexes back.
@db_add_index('url_alias', 'source_language_pid', array('source', 'language', 'pid'));
@db_add_index('url_alias', 'alias_language_pid', array('alias', 'language', 'pid'));

The code has been written basing on the update code used from the System module when updating a previous Drupal version. The part I added is the one to create the database fields, since database fields are normally created during a Drupal installation.