Can't update database: Syntax error or access violation: 1075 Incorrect table definition

Created on 17 February 2022, over 2 years ago
Updated 21 November 2023, 7 months ago

Problem/Motivation

When trying to update the database I get the following issue report:

[error]  SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key: ALTER TABLE "users" DROP PRIMARY KEY; Array
[error]  Update failed: user_update_9301 
[error]  Update aborted by: user_update_9301 
[error]  Finished performing updates. 

What can I do to fix this?

πŸ’¬ Support request
Status

Closed: duplicate

Version

9.3

Component
DatabaseΒ  β†’

Last updated about 18 hours ago

  • Maintained by
  • πŸ‡³πŸ‡±Netherlands @daffie
Created by

πŸ‡³πŸ‡±Netherlands zebda

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¦πŸ‡ΊAustralia taggartj

    This is still an issue in drupal 10 please see

    /**
     * Adds a prime key id so I can finish early today. 
     */
    function MYMODULE_update_8002() {
      // Add a prime key for views base.
      $spec = [
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ];
      $db = \Drupal::database();
      $schema = $db->schema();
    
      if ($schema->fieldExists('some_custom_table', 'id')) {
        $schema->dropField('some_custom_table', 'id');
      }
       
      // THESE HERE Don't work as they should 
      //$schema->addField('some_custom_table', 'id', $spec, ['id']);
      //$schema->addPrimaryKey('some_custom_table', ['id']);
    
      // Resulting to hackery. 
      $table = 'some_custom_table';
      $col = 'id';
      $db->query('ALTER TABLE {' . $table . '} ADD {'. $col .'} INT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY ({'. $col .'})');
    }
    
Production build 0.69.0 2024