Database migration to 1.17.0 fails on mariadb #827

Closed
opened 2026-02-04 22:54:05 +03:00 by OVERLORD · 7 comments
Owner

Originally created by @ToeiRei on GitHub (Oct 11, 2020).

Originally assigned to: @BlackDex on GitHub.

Subject of the issue

#1005 - Can't create table bitwarden.favorites (errno: 150 "Foreign key constraint is incorrectly formed")

Your environment

  • Bitwarden_rs version:
    1.16.3
  • Install method: docker-compose using bitwardenrs/server-mysql
  • Clients used:
  • Reverse proxy and version:
  • Version of mysql/postgresql: 10.5.6-MariaDB-1:10.5.6+maria~buster - mariadb.org binary distribution
  • Other relevant information:

Steps to reproduce

  1. Install 1.16.3
  2. Update to 1.17.0

Expected behaviour

I would expect the database migration to work

Actual behaviour

Docker container looped on starting the migrations. Trying to run it manually it said #1005 - Can't create table `bitwarden`.`favorites` (errno: 150 "Foreign key constraint is incorrectly formed")

which is related to

CREATE TABLE favorites (
  user_uuid   CHAR(36) NOT NULL REFERENCES users(uuid),
  cipher_uuid CHAR(36) NOT NULL REFERENCES ciphers(uuid),

  PRIMARY KEY (user_uuid, cipher_uuid)
);

in the up script

Relevant logs

Originally created by @ToeiRei on GitHub (Oct 11, 2020). Originally assigned to: @BlackDex on GitHub. ### Subject of the issue <!-- Describe your issue here.--> `#1005 - Can't create table bitwarden.favorites (errno: 150 "Foreign key constraint is incorrectly formed")` ### Your environment <!-- The version number, obtained from the logs or the admin page --> * Bitwarden_rs version: 1.16.3 * Install method: docker-compose using bitwardenrs/server-mysql * Clients used: <!-- if applicable --> * Reverse proxy and version: <!-- if applicable --> * Version of mysql/postgresql: 10.5.6-MariaDB-1:10.5.6+maria~buster - mariadb.org binary distribution * Other relevant information: ### Steps to reproduce <!-- Tell us how to reproduce this issue. What parameters did you set (differently from the defaults) and how did you start bitwarden_rs? --> 1. Install 1.16.3 2. Update to 1.17.0 ### Expected behaviour <!-- Tell us what should happen --> I would expect the database migration to work ### Actual behaviour <!-- Tell us what happens instead --> Docker container looped on starting the migrations. Trying to run it manually it said ``#1005 - Can't create table `bitwarden`.`favorites` (errno: 150 "Foreign key constraint is incorrectly formed")`` which is related to ``` CREATE TABLE favorites ( user_uuid CHAR(36) NOT NULL REFERENCES users(uuid), cipher_uuid CHAR(36) NOT NULL REFERENCES ciphers(uuid), PRIMARY KEY (user_uuid, cipher_uuid) ); ``` in the up script ### Relevant logs <!-- Share some logfiles, screenshots or output of relevant programs with us. -->
Author
Owner

@BlackDex commented on GitHub (Oct 11, 2020):

This is weird, i just did the exact same, and have no issues.

Also using the same mariadb version

mariadb  Ver 15.1 Distrib 10.5.6-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

It is also strange that you can see these error's at all, because foreign-key checking is disabled during migrations because the migrations could create these issues when the order is not completely ok, or we need to do some specials stuff like migrating some data from table x to y.

If you start the server again, does it still produce the same error?
And what if you restart MariaDB first?

@BlackDex commented on GitHub (Oct 11, 2020): This is weird, i just did the exact same, and have no issues. Also using the same mariadb version ``` mariadb Ver 15.1 Distrib 10.5.6-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 ``` It is also strange that you can see these error's at all, because foreign-key checking is disabled during migrations because the migrations could create these issues when the order is not completely ok, or we need to do some specials stuff like migrating some data from table x to y. If you start the server again, does it still produce the same error? And what if you restart MariaDB first?
Author
Owner

@ToeiRei commented on GitHub (Oct 11, 2020):

image

That's all I get - even with a restart - no matter if I restart rancherOS or the mariaDB debian container

@ToeiRei commented on GitHub (Oct 11, 2020): ![image](https://user-images.githubusercontent.com/5990591/95683348-fffdad80-0bea-11eb-851d-9d81e2d48de7.png) That's all I get - even with a restart - no matter if I restart rancherOS or the mariaDB debian container
Author
Owner

@BlackDex commented on GitHub (Oct 11, 2020):

Wel that is strange. It looks like it is trying to retry it a few times.

@BlackDex commented on GitHub (Oct 11, 2020): Wel that is strange. It looks like it is trying to retry it a few times.
Author
Owner

@ToeiRei commented on GitHub (Oct 11, 2020):

I got into the error and I think I got a clue: Collation mismatches. Not a big deal.

@ToeiRei commented on GitHub (Oct 11, 2020): I got into the error and I think I got a clue: Collation mismatches. Not a big deal.
Author
Owner

@BlackDex commented on GitHub (Oct 11, 2020):

Great that you have find the solution.
Could the collation setting being something we need to check, verify or warn on?

@BlackDex commented on GitHub (Oct 11, 2020): Great that you have find the solution. Could the collation setting being something we need to check, verify or warn on?
Author
Owner

@ToeiRei commented on GitHub (Oct 12, 2020):

I would suggest verifying those wouldn't hurt. In my case I think it happened via migrating via various MySQL/MariaDB hosts...

@ToeiRei commented on GitHub (Oct 12, 2020): I would suggest verifying those wouldn't hurt. In my case I think it happened via migrating via various MySQL/MariaDB hosts...
Author
Owner

@BlackDex commented on GitHub (Oct 12, 2020):

Thanks, i have added this to the meta feature request #246

@BlackDex commented on GitHub (Oct 12, 2020): Thanks, i have added this to the meta feature request #246
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/vaultwarden#827