Problem connecting to database with env var #2778

Closed
opened 2026-02-28 03:06:55 -05:00 by deekerman · 6 comments
Owner

Originally created by @vonbarnekowa on GitHub (Nov 13, 2023).

⚠️ Please verify that this bug has NOT been raised before.

  • I checked and didn't find similar issue

🛡️ Security Policy

Description

When I run Uptime Kuma with the UPTIME_KUMA_DB_PORT, UPTIME_KUMA_DB_PASSWORD, UPTIME_KUMA_DB_NAME, UPTIME_KUMA_DB_TYPE and UPTIME_KUMA_DB_HOSTNAME environment variables, I can't get the application to work. I get the following error:

[2023-11-13 07:48:55] 2023-11-13T07:48:55Z [DB] ERROR: Database migration failed [2023-11-13 07:48:55] 2023-11-13T07:48:55Z [SERVER] ERROR: Failed to prepare your database: create table knex_migrations (id int unsigned not null auto_increment primary key, name varchar(255), batch int, migration_time timestamp) - No database selected

I don't understand because the tables already exist in the database of a previous installation. I've also tried to create a new database but I get the same errors.

I guess there must be a problem loading the values.

(Moreover, the existence of these env variables is not documented.)

👟 Reproduction steps

  • Ajouter les variables d'environnement qui permettent la connexion sur une base de données existante
  • Lancer Uptime Kuma

👀 Expected behavior

The desired behavior is that the values passed by the environment variables are used. In addition, it should detect that values already exist and skip the table creation part.

😓 Actual Behavior

It displays an error indicating that no database has been set.

🐻 Uptime-Kuma Version

1.23.3

💻 Operating System and Arch

--

🌐 Browser

Brave 1.59.122

🐋 Docker Version

--

🟩 NodeJS Version

v21.1.0

📝 Relevant log output

No response

Originally created by @vonbarnekowa on GitHub (Nov 13, 2023). ### ⚠️ Please verify that this bug has NOT been raised before. - [X] I checked and didn't find similar issue ### 🛡️ Security Policy - [X] I agree to have read this project [Security Policy](https://github.com/louislam/uptime-kuma/security/policy) ### Description When I run Uptime Kuma with the UPTIME_KUMA_DB_PORT, UPTIME_KUMA_DB_PASSWORD, UPTIME_KUMA_DB_NAME, UPTIME_KUMA_DB_TYPE and UPTIME_KUMA_DB_HOSTNAME environment variables, I can't get the application to work. I get the following error: ` [2023-11-13 07:48:55] 2023-11-13T07:48:55Z [DB] ERROR: Database migration failed [2023-11-13 07:48:55] 2023-11-13T07:48:55Z [SERVER] ERROR: Failed to prepare your database: create table knex_migrations (id int unsigned not null auto_increment primary key, name varchar(255), batch int, migration_time timestamp) - No database selected` I don't understand because the tables already exist in the database of a previous installation. I've also tried to create a new database but I get the same errors. I guess there must be a problem loading the values. _(Moreover, the existence of these env variables is not documented.)_ ### 👟 Reproduction steps - Ajouter les variables d'environnement qui permettent la connexion sur une base de données existante - Lancer Uptime Kuma ### 👀 Expected behavior The desired behavior is that the values passed by the environment variables are used. In addition, it should detect that values already exist and skip the table creation part. ### 😓 Actual Behavior It displays an error indicating that no database has been set. ### 🐻 Uptime-Kuma Version 1.23.3 ### 💻 Operating System and Arch -- ### 🌐 Browser Brave 1.59.122 ### 🐋 Docker Version -- ### 🟩 NodeJS Version v21.1.0 ### 📝 Relevant log output _No response_
deekerman 2026-02-28 03:06:55 -05:00
  • closed this issue
  • added the
    help
    label
Author
Owner

@louislam commented on GitHub (Nov 13, 2023):

I think you should follow the installation guide again and install it correctly, because it is not in the 1.23.X version.

@louislam commented on GitHub (Nov 13, 2023): I think you should follow the installation guide again and install it correctly, because it is not in the 1.23.X version.
Author
Owner

@vonbarnekowa commented on GitHub (Nov 13, 2023):

The place where I deploy this has no persistence to store the db-config.json and it's overkill to mount an s3 on purpose for a single file. If I don't do it with environment variables, I always have to reconfigure the database when my container restarts.

Isn't it simpler to try to make the existing codebase work? Especially as it's really useful to be able to use environment variables. I imagine I'm not the only one who wants this.

But if you say you're not going to make any changes, I'll adapt the code on my side. It's not a big deal, I'm just trying to get the codebase working as expected so that the project becomes even better.

@vonbarnekowa commented on GitHub (Nov 13, 2023): The place where I deploy this has no persistence to store the db-config.json and it's overkill to mount an s3 on purpose for a single file. If I don't do it with environment variables, I always have to reconfigure the database when my container restarts. Isn't it simpler to try to make the existing codebase work? Especially as it's really useful to be able to use environment variables. I imagine I'm not the only one who wants this. But if you say you're not going to make any changes, I'll adapt the code on my side. It's not a big deal, I'm just trying to get the codebase working as expected so that the project becomes even better.
Author
Owner

@vonbarnekowa commented on GitHub (Nov 13, 2023):

The problem comes from the server/setup-database.js file on line 77. It should be

dbConfig.dbName = process.env.UPTIME_KUMA_DB_NAME;

instead of

dbConfig.database = process.env.UPTIME_KUMA_DB_NAME;

I'm going to test everything and make a PR if you think it's useful.

@vonbarnekowa commented on GitHub (Nov 13, 2023): The problem comes from the `server/setup-database.js` file on line 77. It should be `dbConfig.dbName = process.env.UPTIME_KUMA_DB_NAME;` instead of `dbConfig.database = process.env.UPTIME_KUMA_DB_NAME;` I'm going to test everything and make a PR if you think it's useful.
Author
Owner

@louislam commented on GitHub (Nov 13, 2023):

Since you said 1.23.3, I assumed that you didn't installed correctly.

What you are looking at is the code from dev (2.0.X) branch, they are unreleased and unstable. They are under development and maybe it is actually a bug. I highly recommend that you should not use that for production for any reasons.

@louislam commented on GitHub (Nov 13, 2023): Since you said `1.23.3`, I assumed that you didn't installed correctly. What you are looking at is the code from dev (2.0.X) branch, they are unreleased and unstable. They are under development and maybe it is actually a bug. I highly recommend that you should not use that for production for any reasons.
Author
Owner

@vonbarnekowa commented on GitHub (Nov 13, 2023):

I'm using version 1.23.3. I simply forked the master branch which seems to be in this version. I don't see anything from 2.0.X.

Line

@vonbarnekowa commented on GitHub (Nov 13, 2023): I'm using version 1.23.3. I simply forked the `master` branch which seems to be in this version. I don't see anything from 2.0.X. [Line](https://github.com/louislam/uptime-kuma/blob/master/server/setup-database.js#L77 )
Author
Owner

@chakflying commented on GitHub (Nov 13, 2023):

The master branch has been 2.0 since #2720 was merged. Yes you have found a bug, but even if you fix that line, the code still expects the config to be written to the json file. I don't think you can trivially fix this, and there may be other known or unknown bugs that are not fixed yet.

If you just want to use the application, please follow the installation guide and checkout 1.23.4.

@chakflying commented on GitHub (Nov 13, 2023): The master branch has been 2.0 since #2720 was merged. Yes you have found a bug, but even if you fix that line, the code still expects the config to be written to the json file. I don't think you can trivially fix this, and there may be other known or unknown bugs that are not fixed yet. If you just want to use the application, please follow the installation guide and `checkout 1.23.4`.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/uptime-kuma#2778
No description provided.