Skip to content

Auto Upgrade from 5.0.7 to 5.0.8 Fails With MySQL Query Error #4085

Closed

Description

@ValleyGeek

I attempted an auto upgrade from the admin interface which has resulted in the below error. I didn't see any other similar issues out there and I am not certain how I should proceed to resolve this - possibly something to do with with calendar app.

Workaround methods listed in comments

Expected behaviour

A successful update to version 5.0.8

Actual behaviour

Upgrade fails and error displayed.
owncloud message on update

Steps to reproduce

Unknown - I did modify a couple files to make the files sizes display better a while back but have had no issues until this update.

https://github.com/owncloud/core/issues/633

Displaying human readable file sizes is more useful for me, and a number of other users. I understand the reasoning behind not displaying the human readable size by default, but could it the change be implemented as an option to switch between the two options globally or per user?

I made a couple small changes on my install to display the human readable sizes that worked well.

edit core/js/js.js
comment out the existing simpleFileSize function (line ~642) using // on each line or /** on first line and **/ on last line
Add your own function as follows:

function simpleFileSize(size) {
        return humanFileSize(size);
}

edit lib/template.php
comment out the existing simple_file_size function (line ~71)
Add your own function as follows:

function simple_file_size( $bytes ) {
        return OC_Helper::humanFileSize( $bytes );
}

Server configuration

Operating system: Ubuntu 13.04

Web server: Apache 2.2.22 (Ubuntu)

Database: MySQL 5.5.31

PHP version: PHP Version 5.4.9

ownCloud version: Should be 5.0.8 (config.php: 'version' => '5.0.12',)

Client configuration

Browser: Firefox v22.0

Operating system: Windows 7 x64

Logs

Web server error log

No Output Generated

ownCloud log (data/owncloud.log) - Set to Debug Level

{"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1373988159}
{"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1373988159}
{"app":"calendar","message":"starting app upgrade from 0.6.1 to 0.6.3","level":0,"time":1373988159}
{"app":"core","message":"Failed to update database structure (MDB2 Error: unknown error, _doQuery: [Error message: Could not execute statement]\n[Last executed query: ALTER TABLE `oc_calendar_objects` RENAME TO `oc_clndr_objects`, CHANGE `id` `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CHANGE `calendarid` `calendarid` INT UNSIGNED DEFAULT 0 NOT NULL, CHANGE `startdate` `startdate` DATETIME DEFAULT '1970-01-01 00:00:00', CHANGE `enddate` `enddate` DATETIME DEFAULT '1970-01-01 00:00:00']\n[Native code: 1068]\n[Native message: Multiple primary key defined]\n)","level":4,"time":1373988160}
{"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1373988160}
{"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1373988160}
{"app":"core","message":"starting upgrade from 5.0.12 to 5.0.14","level":2,"time":1373988160}
{"app":"core","message":"Failed to update database structure (MDB2 Error: unknown error, _doQuery: [Error message: Could not execute statement]\n[Last executed query: ALTER TABLE `oc_locks` CHANGE `id` `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CHANGE `timeout` `timeout` INT UNSIGNED DEFAULT 0, CHANGE `created` `created` BIGINT DEFAULT 0, CHANGE `scope` `scope` TINYINT DEFAULT 0, CHANGE `depth` `depth` TINYINT DEFAULT 0]\n[Native code: 1068]\n[Native message: Multiple primary key defined]\n)","level":4,"time":1373988161}
{"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1373988161}

Browser log

N/A

Activity

  1. Niduroki commented on Jul 16, 2013

    @Niduroki

    @RealRancor it's not exactly the same issue though … #4084 is 5.0.8->5.0.9.
    This is 5.0.7->5.0.8.

    The error message is the same though.

  2. ValleyGeek commented on Jul 16, 2013

    @ValleyGeek
    Author

    Ha, well I sure feel blind now, they are indeed the same error. Although I can see an argument for the version making them two separate issues. If it is decided to merge them, I have no issues with that. In any case, any advice is appreciated. I thought I should report it here before I begin hacking at it.

  3. ValleyGeek commented on Jul 17, 2013

    @ValleyGeek
    Author

    @RealRancor Thanks for the followup on the calendar. I took the steps outlined by @georgehrke #4013 (comment)

    Upon refresh of my installation I am presented with the same UI output as pictured in my OP but my owncloud.log output is shorter as follows:

    {"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1374044147}
    {"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1374044147}
    {"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1374044147}
    {"app":"core","message":"starting upgrade from 5.0.12 to 5.0.14","level":2,"time":1374044147}
    {"app":"core","message":"Failed to update database structure (MDB2 Error: unknown error, _doQuery: [Error message: Could not execute statement]\n[Last executed query: ALTER TABLE `oc_locks` CHANGE `id` `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CHANGE `timeout` `timeout` INT UNSIGNED DEFAULT 0, CHANGE `created` `created` BIGINT DEFAULT 0, CHANGE `scope` `scope` TINYINT DEFAULT 0, CHANGE `depth` `depth` TINYINT DEFAULT 0]\n[Native code: 1068]\n[Native message: Multiple primary key defined]\n)","level":4,"time":1374044148}
    {"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1374044148}
    {"app":"core","message":"Adding user backend instance of OC_User_Database.","level":0,"time":1374044148}
    

    For reference, here is the schema for my oc_locks table:

    mysql> describe oc_locks;
    +---------+------------------+------+-----+---------+----------------+
    | Field   | Type             | Null | Key | Default | Extra          |
    +---------+------------------+------+-----+---------+----------------+
    | id      | int(11)          | NO   | PRI | NULL    | auto_increment |
    | userid  | varchar(64)      | YES  |     | NULL    |                |
    | owner   | varchar(100)     | YES  |     | NULL    |                |
    | timeout | int(10) unsigned | YES  |     | 0       |                |
    | created | bigint(20)       | YES  |     | 0       |                |
    | token   | varchar(100)     | YES  |     | NULL    |                |
    | scope   | smallint(6)      | YES  |     | 0       |                |
    | depth   | smallint(6)      | YES  |     | 0       |                |
    | uri     | longtext         | YES  |     | NULL    |                |
    +---------+------------------+------+-----+---------+----------------+
    9 rows in set (0.00 sec)

    I am happy to try and test any suggestions or provide further information as able. I would like to get my installation back up soon, but I don't have an urgent need.

    On a semi-related note, I notice that I now have Apache and PHP updates available. I have not installed them yet so that my environment would be consistent for troubleshooting. However, I can and will install them if asked to.

    The following packages will be upgraded:
      apache2 apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 libxml2 libxml2-utils php-pear php5 php5-cli php5-common php5-curl php5-gd php5-intl php5-mysql php5-sqlite
    
  4. brotkastn commented on Jul 21, 2013

    @brotkastn

    I can confirm problems with the upgrade to 5.0.9, this is what i am getting:
    {"app":"core","message":"starting upgrade from 5.0.12 to 5.0.15","level":2,"time":1374433237}
    {"app":"core","message":"Failed to update database structure (MDB2 Error: unknown error, _doQuery: [Error message: Could not execute statement]\n[Last executed query: ALTER TABLE oc_locks CHANGE id id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CHANGE timeout timeout INT UNSIGNED DEFAULT 0, CHANGE created created BIGINT DEFAULT 0, CHANGE scope scope TINYINT DEFAULT 0, CHANGE depth depth TINYINT DEFAULT 0]\n[Native code: 1068]\n[Native message: Multiple primary key defined]\n)","level":4,"time":1374433240}

    This is on a debian-vm, using PostgreSQL (9.3) as the DB-Backend

  5. tanatospl commented on Jul 23, 2013

    @tanatospl

    I had this problem too (Multiple primary key defined).

    The problem here is that mysql does not allow to alter primary key of a table without deleting that key first.
    I fixed this problem by going to phpmyadmin and manually deleting primary keys for tables like: locks, queuedtasks, vcategory, calendar* etc... and then refreshing my owncloud page. This restarted the update procedure and fixed the problem.

    The long term fix would be to change the owncloud updater code to always add "ALTER TABLE tablename DROP PRIMARY KEY" before executing any primary key altering on mysql.

  6. ValleyGeek commented on Jul 24, 2013

    @ValleyGeek
    Author

    Following the advice of @tanatospl I ran the commands below against my database (one at a time) refreshing my ownCloud root page after each table change and have successfully completed the update with no changes other than what has been mentioned in this issue.

    The first line in each pair was to remove the "Auto Increment" from the id fields (MySQL error: "ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key") and the second is to remove the primary key attribute.

    ALTER TABLE `oc_locks` CHANGE `id` `id` INT( 11 ) NOT NULL;
    ALTER TABLE `oc_locks` DROP PRIMARY KEY;
    ALTER TABLE `oc_queuedtasks` CHANGE `id` `id` INT( 11 ) NOT NULL;
    ALTER TABLE `oc_queuedtasks` DROP PRIMARY KEY;
    ALTER TABLE `oc_vcategory` CHANGE `id` `id` INT( 11 ) NOT NULL;
    ALTER TABLE `oc_vcategory` DROP PRIMARY KEY;

    At this time I am no longer affected by this issue. I proceeded to immediately run the auto update from 5.0.8 to 5.0.9 and it ran without issue. I didn't close this issue in the event that others are still receiving this and it should be left open but I have no personal reason for it to be left open.

  7. brotkastn commented on Jul 28, 2013

    @brotkastn

    So, what is the official way to upgrade then? Since i guess it shouldnt involve the users to execute own statements like @ValleyGeek , i guess the upgrade script should check which db it runs on and try to do the right thing.

  8. karlitschek commented on Jul 28, 2013

    @karlitschek
    Contributor

    Could you try to upgrade to 5.0.9 please? We fixed a few bugs here.

  9. brotkastn commented on Jul 28, 2013

    @brotkastn

    As stated before, this was while trying to upgrade to 5.0.9.

  10. brotkastn commented on Aug 21, 2013

    @brotkastn

    After trying to upgrade to 5.0.10, this is what the owncloud.log contains.

    {"app":"core","message":"Failed to update database structure (MDB2 Error: unknown error, _doQuery: [Error message: Could not execute statement] \n[Last executed query: ALTER TABLE oc_calendar_objectsRENAME TOoc_clndr_objects, CHANGE id id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, CHANGEcalendarid calendaridINT UNSIGNED DEFAULT 0 NOT NULL, CHANGEstartdate startdateDATETIME DEFAULT '1970-01-01 00:00:00', CHANGEenddate enddate DATETIME DEFAULT '1970-01-01 00:00:00'] \n[Native code: 1068] \n[Native message: Multiple primary key defined]\n)","level":4,"time":"2013-08-21T22:26:08+00:00"}

  11. 12 remaining items

  12. StrangeNoises commented on Nov 29, 2013

    @StrangeNoises

    every time there's a minor upgrade, it's a different table that needs fixing; but it's always the same problem; the fix being to remove the primary key index and then try the command listed in the error message again. it seems odd to me that it only errors on one table per upgrade and then is seemingly happy with the rest, until the next upgrade, when the next table needs it done...

  13. StrangeNoises commented on Nov 29, 2013

    @StrangeNoises

    I first encountered this on 5.0.11 (before which I switched to mysql) (reported originally in my now-closed dupe bug #4809, now on 5.0.13 so actually it's only happened 3 times for me. FYI my entire .mysql_history from that time:

    show create table oc_locks;
    describe oc_locks;
    ALTER TABLE `oc_locks` CHANGE `id` `id` INT( 11 ) NOT NULL;
    ALTER TABLE `oc_locks` DROP PRIMARY KEY;
    describe oc_queuedtasks;
    describe oc_locks;
    ALTER TABLE `oc_queuedtasks` CHANGE `id` `id` INT( 11 ) NOT NULL;
    ALTER TABLE `oc_queuedtasks` DROP PRIMARY KEY;
    ALTER TABLE `oc_vcategory` DROP PRIMARY KEY;
    describe oc_vcategory
    ;
    ALTER TABLE `oc_vcategory` DROP PRIMARY KEY;
    alter table `oc_vcategory` change `id` `id` int unsigned not null;
    describe oc_vcategory;
    alter table `oc_vcategory` change `id` `id` int unsigned not null auto_increment primary key;
    describe oc_vcategory;
    ALTER TABLE `oc_vcategory` DROP PRIMARY KEY;
    describe oc_vcategory;
    alter table `oc_vcategory` change `id` `id` int unsigned not null auto_increment primary key;
    describe oc_vcategory;
    alter table `oc_vcategory` CHANGE `uid` `uid` VARCHAR(64) DEFAULT ' ' NOT NULL, CHANGE `type` `type` VARCHAR(64) DEFAULT ' ' NOT NULL, CHANGE `category` `category` VARCHAR(255) DEFAULT ' ' NOT NULL;
    describe oc_vcategory;
    

    ... which reminds me I did have some extra problem with the most recent time, with oc_vcategory.

    But mostly included in case the order in which the tables are failing is illuminating...

  14. ayedoit commented on Dec 5, 2013

    @ayedoit

    So you're saying, you already had the problem before the migration?

  15. StrangeNoises commented on Dec 5, 2013

    @StrangeNoises

    before the migration to mysql? no, only had this problem since.

  16. StrangeNoises commented on Dec 5, 2013

    @StrangeNoises

    that 'before which'... means that up until 5.0.10 I had been running it on the default sqlite db; but i was having extreme problems when trying to sync lots of files to multiple clients (that was the point at which i finally switched everything from dropbox, so everything got dropped in at once), so that's when I did the migration, as described, to mysql.

    Then later than that, 5.0.11 came out and I upgraded... and this happened; and since then, with each minor-version upgrade, ie: from 5.0.10 to 5.0.11, to 5.0.12, to 5.0.13. Hence my rather dreading what's going to happen going up to version 6. :-}

  17. karlitschek commented on Dec 5, 2013

    @karlitschek
    Contributor

    Awesome. This makes me really angry. This howto/conversion script that was publish on some 3rd party website killed another instance. Sorry @StrangeNoises but there is nothing we can do here. This db conversion changed your db structure in a way so that it can't be upgraded again.
    :-(

  18. StrangeNoises commented on Dec 5, 2013

    @StrangeNoises

    right well, i'm the only user of my instance. I'm in principle ok with starting afresh, but is there a better solution to the reason i did that migration anyway? which seems to have been that the sqlite implementation just gets hopelessly bogged down with any kind of concurrency requirements?

    For my part, I'm actually more comfortable with postgresql, which I use in my day job, as being much more like a proper DB. I only didn't do it that way at the time as there wasn't a howto for the migration that came up in my searches...

  19. Wikinaut commented on Dec 5, 2013

    @Wikinaut
    Contributor

    Can someone (of you experts in commenting) please develop a clean ownCloud-SQlite-starter to MySQL-professional-user database converter, and also a Database-First-Aid-kit ?

    I mean, a robust and error-resistant piece of maintenance software which repairs an ownCloud database. This is really needed. Unfortunately, I am not familiar with the ownCloud database table schema.

  20. ayedoit commented on Dec 5, 2013

    @ayedoit

    Then maybe you should get familiar with it, you expert in commenting...

  21. karlitschek commented on Dec 6, 2013

    @karlitschek
    Contributor

    Could you please calm down guys?
    ownCloud is a volunteer project so we have to see if someone writes a working conversion script.
    Someone should also work on a fix-broken-converted-databases routine. Are you interested @ayedoit ?

  22. StrangeNoises commented on Dec 13, 2013

    @StrangeNoises

    FWIW, resolved my issues by nuking the site from orbit and installing owncloud 6 from scratch, configuring it from the outset (as opposed to trusting a future migration is possible) to use postgresql, using the information in the owncloud 6 admin manual to do so. All seems to be progressing smoothly (still re-syncing content which I'd thankfully backed up locally).

    This wasn't too painful for me as I'm the only user of my owncloud install, and I had only been using it for basic file storage, no app use. Others might not be in that situation, so I'd say there probably is still an audience for migration guides/utilities; mainly because it may not be obvious at the outset (wasn't for me when I first installed it) that an sqlite-based install will have some severe performance limitations even for a single user (albeit with multiple client devices).

    (Using postgresql rather than mysql because that's what I work with in my day job, so if I have to hack at it to fix stuff later, I can do so with a lot more confidence than I could with mysql. No need for any such hacking-at yet, so far; just gone by the admin manual.)

    minor notelets:

    1: The only postgresql dependencies I used (on Ubuntu 12.04) were postgresql-9.1 and php5-pgsql (and obviously the dependencies they bring in). Might be nice to add an owncloud-pgsql meta package to do that, like I see there now is for sqlite and mysql. :)

    2: I didn't need to worry about writing the db connection params into config.php as the initial configuration wizard does that now. Might be reassuring to say so. :)

    3: "sudo -u postgres psql" won't ask the user for an unknown (and in fact unset) password.

  23. VicDeo commented on Feb 8, 2014

    @VicDeo
    Contributor

    Closing as a duplicate of #999
    IICR All instances that migrated from sqlite to Mysql are affected

  24. locked as resolved and limited conversation to collaborators on Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions