Error (index "primary" does not exist) when migrating SQLite → Postgres

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 20.0.5): 20
Operating system and version (eg, Ubuntu 20.04): official docker container nextcloud:20

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Create a new database in Postgres

  2. Attempt to migrate from SQLite to Postgres via

    php occ db:convert-type --password=“e…q” pgsql nextcloud postgres nextcloud

The output of your Nextcloud log in Admin > Logging the prompt within the docker container:

www-data@f4145bc6612f:~/html$ php occ db:convert-type --password="e..q" pgsql nextcloud postgres nextcloud
Creating schema in new database

In AbstractPostgreSQLDriver.php line 79:

  An exception occurred while executing 'DROP INDEX "primary"':

  SQLSTATE[42704]: Undefined object: 7 ERROR:  index "primary" does not exist


In PDOConnection.php line 83:

  SQLSTATE[42704]: Undefined object: 7 ERROR:  index "primary" does not exist


In PDOConnection.php line 78:

  SQLSTATE[42704]: Undefined object: 7 ERROR:  index "primary" does not exist


db:convert-type [--port PORT] [--password PASSWORD] [--clear-schema] [--all-apps] [--chunk-size CHUNK-SIZE] [--] <type> <username> <hostname> <database>

www-data@f4145bc6612f:~/html$

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'o....y',
  'passwordsalt' => 'Y...x',
  'secret' => 'T...b',
  'trusted_domains' => 
  array (
    0 => 'nextcloud.MY.DOMAIN',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'sqlite3',
  'version' => '20.0.5.2',
  'overwrite.cli.url' => 'https://nextcloud.MY.DOMAIN',
  'overwriteprotocol' => 'https',
  'auth.bruteforce.protection.enabled' => false,
  'installed' => true,
  'has_rebuilt_cache' => true,
  'maintenance' => false,
  'theme' => '',
  'loglevel' => 2,
  'mail_from_address' => 'nextcloud',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => 'smtp',
  'mail_domain' => 'swtk.info',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_smtpauth' => 1,
  'mail_smtphost' => 'smtp.orange.fr',
  'mail_smtpsecure' => 'ssl',
  'mail_smtpport' => '465',
  'mail_smtpname' => 'XXX@orange.fr',
  'mail_smtppassword' => 'XXX',
  'has_internet_connection' => true,
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
  'filelocking.enabled' => true,
  'trusted_proxies' => 
  array (
    0 => '172.19.0.31',
  ),
  'forwarded_for_headers' => 
  array (
    0 => 'HTTP_X_FORWARDED_FOR',
  ),
  'app_install_overwrite' => 
  array (
    0 => 'mindmap_app',
    1 => 'twofactor_yubikey',
  ),
);

NOTE: I use double a multiple factor authentication, I saw some old (3+ years) discussions about issues with that when migrating (not necessarily from SQLite)

Before you start migrating to the new database format (SQLite -> PostgreSQL), you should make sure that the current database contains all columns, indices and primary keys. By executing different occ commands you can verify the structure of the database:

  db:add-missing-columns                 Add missing optional columns to the database tables
  db:add-missing-indices                 Add missing indices to the database tables
  db:add-missing-primary-keys            Add missing primary keys to the database tables

Thank you for your reply.

I launched the 3 commands, deleted the existing PG DB, created a new one, re-launched the migration and I get exactly the same errors

Depending on the following posting you should try to disable all 3rd-party apps and try again:

Thanks. I disabled the apps and the conversion is ongoing.

I am afraid that I will lose all the data in these apps (The following tables will not be converted…) but this is not a disaster either at that point.

I will update as it finishes. EDIT: it finished successfully

Thanks for this topic,

disabling all 3rd-party apps
+
db:add-missing-columns
db:add-missing-indices
db:add-missing-primary-keys

Did not work, I got the same error messages.

After I removed the 3rd party apps(maybe only 2FA), I was able to convert my NC 20.0.14 with MariaDB 5.5.57.
(And also finally to upgrade to NC23)

1 Like