[GH-ISSUE #12975] issue: Database setup fails when requiring a non-default schema #16773

Closed
opened 2026-04-19 22:36:54 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @matthew-kusz on GitHub (Apr 17, 2025).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/12975

Check Existing Issues

  • I have searched the existing issues and discussions.
  • I am using the latest version of Open WebUI.

Installation Method

Docker

Open WebUI Version

0.6.5

Ollama Version (if applicable)

No response

Operating System

RHEL 9.5

Browser (if applicable)

No response

Confirmation

  • I have read and followed all instructions in README.md.
  • I am using the latest version of both Open WebUI and Ollama.
  • I have included the browser console logs.
  • I have included the Docker container logs.
  • I have listed steps to reproduce the bug in detail.

Expected Behavior

I expect the tables to be created without issue.

Actual Behavior

When running open-webui and setting up a postgreql database that requires a non-default schema I am running into an error even after setting the DATABASE_SCHEMA env variable:

INFO:open_webui.internal.db:Starting migrations
DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "migrated_at" TIMESTAMP NOT NULL)', [])
ERROR:open_webui.internal.db:Failed to initialize the database connection: no schema has been selected to create in
LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT...
                                   ^

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/peewee.py", line 3322, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.errors.InvalidSchemaName: no schema has been selected to create in
LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT...

Steps to Reproduce

Run open-webui with a postgresql db that requires a non-default schema.

Logs & Screenshots

INFO:open_webui.internal.db:Starting migrations
DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "migrated_at" TIMESTAMP NOT NULL)', [])
ERROR:open_webui.internal.db:Failed to initialize the database connection: no schema has been selected to create in
LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT...
                                   ^

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/peewee.py", line 3322, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.errors.InvalidSchemaName: no schema has been selected to create in
LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT...

Additional Information

It looks like it's related to this line which doesn't include a non-default schema if needed.

# Workaround to handle the peewee migration
# This is required to ensure the peewee migration is handled before the alembic migration
def handle_peewee_migration(DATABASE_URL):
    # db = None
    try:
        # Replace the postgresql:// with postgres:// to handle the peewee migration
        db = register_connection(DATABASE_URL.replace("postgresql://", "postgres://"))
        migrate_dir = OPEN_WEBUI_DIR / "internal" / "migrations"
        router = Router(db, logger=log, migrate_dir=migrate_dir)
        router.run()
        db.close()

    except Exception as e:
        log.error(f"Failed to initialize the database connection: {e}")
        raise
    finally:
        # Properly closing the database connection
        if db and not db.is_closed():
            db.close()

        # Assert if db connection has been closed
        assert db.is_closed(), "Database connection is still open."


handle_peewee_migration(DATABASE_URL)
Originally created by @matthew-kusz on GitHub (Apr 17, 2025). Original GitHub issue: https://github.com/open-webui/open-webui/issues/12975 ### Check Existing Issues - [x] I have searched the existing issues and discussions. - [x] I am using the latest version of Open WebUI. ### Installation Method Docker ### Open WebUI Version 0.6.5 ### Ollama Version (if applicable) _No response_ ### Operating System RHEL 9.5 ### Browser (if applicable) _No response_ ### Confirmation - [x] I have read and followed all instructions in `README.md`. - [x] I am using the latest version of **both** Open WebUI and Ollama. - [x] I have included the browser console logs. - [x] I have included the Docker container logs. - [x] I have listed steps to reproduce the bug in detail. ### Expected Behavior I expect the tables to be created without issue. ### Actual Behavior When running open-webui and setting up a postgreql database that requires a non-default schema I am running into an error even after setting the DATABASE_SCHEMA env variable: ```` INFO:open_webui.internal.db:Starting migrations DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "migrated_at" TIMESTAMP NOT NULL)', []) ERROR:open_webui.internal.db:Failed to initialize the database connection: no schema has been selected to create in LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT... ^ Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/peewee.py", line 3322, in execute_sql cursor.execute(sql, params or ()) psycopg2.errors.InvalidSchemaName: no schema has been selected to create in LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT... ````` ### Steps to Reproduce Run open-webui with a postgresql db that requires a non-default schema. ### Logs & Screenshots ```` INFO:open_webui.internal.db:Starting migrations DEBUG:peewee:('CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "migrated_at" TIMESTAMP NOT NULL)', []) ERROR:open_webui.internal.db:Failed to initialize the database connection: no schema has been selected to create in LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT... ^ Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/peewee.py", line 3322, in execute_sql cursor.execute(sql, params or ()) psycopg2.errors.InvalidSchemaName: no schema has been selected to create in LINE 1: CREATE TABLE IF NOT EXISTS "migratehistory" ("id" SERIAL NOT... ```` ### Additional Information It looks like it's related to this line which doesn't include a non-default schema if needed. ```` # Workaround to handle the peewee migration # This is required to ensure the peewee migration is handled before the alembic migration def handle_peewee_migration(DATABASE_URL): # db = None try: # Replace the postgresql:// with postgres:// to handle the peewee migration db = register_connection(DATABASE_URL.replace("postgresql://", "postgres://")) migrate_dir = OPEN_WEBUI_DIR / "internal" / "migrations" router = Router(db, logger=log, migrate_dir=migrate_dir) router.run() db.close() except Exception as e: log.error(f"Failed to initialize the database connection: {e}") raise finally: # Properly closing the database connection if db and not db.is_closed(): db.close() # Assert if db connection has been closed assert db.is_closed(), "Database connection is still open." handle_peewee_migration(DATABASE_URL) ````
GiteaMirror added the bug label 2026-04-19 22:36:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#16773