An error occurred -- missing column owner_id??? #3507

Closed
opened 2026-02-05 06:55:31 +03:00 by OVERLORD · 9 comments
Owner

Originally created by @MrGibbage on GitHub (Feb 13, 2023).

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

It's been a while since I last fired up my bookstack installation, so I don't know when this started happening. I have an error when I try to go to the bookstack homepage. "An error occurred" without any other information. I can open the settings pages, I can log out and log in, but nothing else. There is an error that shows up in the log.

Any suggestions to getting this fixed?

Exact BookStack Version

23.01.1

Log Content

[2023-02-12 14:21:55] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owner_id' in 'field list' (SQL: select * from activities where (exists (select entity_id, entity_type, max(owner_id) as owner_id, max(status) as status from joint_permissions where activities.entity_id = joint_permissions.entity_id and role_id in (1) and activities.entity_type = joint_permissions.entity_type group by entity_type, entity_id having (status IN (1, 3) or (owner_id = 1 and status != 2)))) and (entity_type != page or exists (select id from pages where pages.id = activities.entity_id and activities.entity_type = page and pages.draft = 0)) order by created_at desc limit 10 offset 0) {"userId":1,"exception":"[object] (Illuminate\Database\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owner_id' in 'field list' (SQL: select * from activities where (exists (select entity_id, entity_type, max(owner_id) as owner_id, max(status) as status from joint_permissions where activities.entity_id = joint_permissions.entity_id and role_id in (1) and activities.entity_type = joint_permissions.entity_type group by entity_type, entity_id having (status IN (1, 3) or (owner_id = 1 and status != 2)))) and (entity_type != page or exists (select id from pages where pages.id = activities.entity_id and activities.entity_type = page and pages.draft = 0)) order by created_at desc limit 10 offset 0) at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712)

PHP Version

No response

Hosting Environment

I am using docker on a synology nas. I use watchtower to keep things up-to-date, so I am guessing something got cross-threaded somewhere recently.

Originally created by @MrGibbage on GitHub (Feb 13, 2023). ### Attempted Debugging - [X] I have read the debugging page ### Searched GitHub Issues - [X] I have searched GitHub for the issue. ### Describe the Scenario It's been a while since I last fired up my bookstack installation, so I don't know when this started happening. I have an error when I try to go to the bookstack homepage. "An error occurred" without any other information. I can open the settings pages, I can log out and log in, but nothing else. There is an error that shows up in the log. Any suggestions to getting this fixed? ### Exact BookStack Version 23.01.1 ### Log Content [2023-02-12 14:21:55] production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owner_id' in 'field list' (SQL: select * from activities where (exists (select entity_id, entity_type, max(owner_id) as owner_id, max(status) as status from joint_permissions where activities.entity_id = joint_permissions.entity_id and role_id in (1) and activities.entity_type = joint_permissions.entity_type group by entity_type, entity_id having (status IN (1, 3) or (owner_id = 1 and status != 2)))) and (entity_type != page or exists (select id from pages where pages.id = activities.entity_id and activities.entity_type = page and pages.draft = 0)) order by created_at desc limit 10 offset 0) {"userId":1,"exception":"[object] (Illuminate\Database\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owner_id' in 'field list' (SQL: select * from activities where (exists (select entity_id, entity_type, max(owner_id) as owner_id, max(status) as status from joint_permissions where activities.entity_id = joint_permissions.entity_id and role_id in (1) and activities.entity_type = joint_permissions.entity_type group by entity_type, entity_id having (status IN (1, 3) or (owner_id = 1 and status != 2)))) and (entity_type != page or exists (select id from pages where pages.id = activities.entity_id and activities.entity_type = page and pages.draft = 0)) order by created_at desc limit 10 offset 0) at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712) ### PHP Version _No response_ ### Hosting Environment I am using docker on a synology nas. I use watchtower to keep things up-to-date, so I am guessing something got cross-threaded somewhere recently.
OVERLORD added the 🐕 Support label 2026-02-05 06:55:31 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Feb 13, 2023):

Hi @MrGibbage,
The error generally indicates that the database is not as-up-to-date as the codebase.
How database changes are applied can depend on the container image used, but generally they'd run database migrations, to apply changes, on container start-up.
You may get some further insight to the error by restarting the bookstack container, and viewing container logs during this start-up process.

@ssddanbrown commented on GitHub (Feb 13, 2023): Hi @MrGibbage, The error generally indicates that the database is not as-up-to-date as the codebase. How database changes are applied can depend on the container image used, but generally they'd run database migrations, to apply changes, on container start-up. You may get some further insight to the error by restarting the bookstack container, and viewing container logs during this start-up process.
Author
Owner

@MrGibbage commented on GitHub (Feb 14, 2023):

Not really much more to go on here. I restarted the bookstack container and this is what was in the log.

Signal handled: Terminated.
[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
usermod: no changes
-------------------------------------
          _         ()
         | |  ___   _    __
         | | / __| | |  /  \
         | | \__ \ | | | () |
         |_| |___/ |_|  \__/
Brought to you by linuxserver.io
-------------------------------------
To support LSIO projects visit:
https://www.linuxserver.io/donate/
-------------------------------------
GID/UID
-------------------------------------
User uid:    1027
User gid:    100
-------------------------------------
using keys found in /config/keys
App Key found - setting variable for seds
Running config - DB_HOST set
Waiting for DB to be available
Migrating: 2022_10_08_104202_drop_entity_restricted_field
   Illuminate\Database\QueryException 
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pages.restricted' in 'on clause' (SQL: select `entity_permissions`.`id` as `id` from `entity_permissions` inner join `pages` on `pages`.`restricted` = 0 and `pages`.`id` = `entity_permissions`.`entity_id` where `entity_type` = page)
  at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }
      +9 vendor frames 
  10  /app/www/database/migrations/2022_10_08_104202_drop_entity_restricted_field.php:26
      Illuminate\Database\Query\Builder::pluck()
  11  /app/www/database/migrations/2022_10_08_104202_drop_entity_restricted_field.php:29
      DropEntityRestrictedField::{closure}()
[custom-init] No custom files found, skipping...
[ls.io-init] done.
@MrGibbage commented on GitHub (Feb 14, 2023): Not really much more to go on here. I restarted the bookstack container and this is what was in the log. ``` Signal handled: Terminated. [migrations] started [migrations] 01-nginx-site-confs-default: skipped [migrations] 02-default-location: skipped [migrations] done usermod: no changes ------------------------------------- _ () | | ___ _ __ | | / __| | | / \ | | \__ \ | | | () | |_| |___/ |_| \__/ Brought to you by linuxserver.io ------------------------------------- To support LSIO projects visit: https://www.linuxserver.io/donate/ ------------------------------------- GID/UID ------------------------------------- User uid: 1027 User gid: 100 ------------------------------------- using keys found in /config/keys App Key found - setting variable for seds Running config - DB_HOST set Waiting for DB to be available Migrating: 2022_10_08_104202_drop_entity_restricted_field Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pages.restricted' in 'on clause' (SQL: select `entity_permissions`.`id` as `id` from `entity_permissions` inner join `pages` on `pages`.`restricted` = 0 and `pages`.`id` = `entity_permissions`.`entity_id` where `entity_type` = page) at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712 708▕ // If an exception occurs when attempting to run a query, we'll format the error 709▕ // message to include the bindings with SQL, which will make this exception a 710▕ // lot more helpful to the developer instead of just the database's errors. 711▕ catch (Exception $e) { ➜ 712▕ throw new QueryException( 713▕ $query, $this->prepareBindings($bindings), $e 714▕ ); 715▕ } 716▕ } +9 vendor frames 10 /app/www/database/migrations/2022_10_08_104202_drop_entity_restricted_field.php:26 Illuminate\Database\Query\Builder::pluck() 11 /app/www/database/migrations/2022_10_08_104202_drop_entity_restricted_field.php:29 DropEntityRestrictedField::{closure}() [custom-init] No custom files found, skipping... [ls.io-init] done. ```
Author
Owner

@ssddanbrown commented on GitHub (Feb 14, 2023):

Thanks @MrGibbage.
So the database migrations appear to be failing, but we can't see the original issue reason here, since re-attempts will show a different error message.
Fundamentally, need to get the database back to the expected state. What's your level of comfort when it comes to database work/commands?

This is much the same as #4012.

@ssddanbrown commented on GitHub (Feb 14, 2023): Thanks @MrGibbage. So the database migrations appear to be failing, but we can't see the original issue reason here, since re-attempts will show a different error message. Fundamentally, need to get the database back to the expected state. What's your level of comfort when it comes to database work/commands? This is much the same as #4012.
Author
Owner

@MrGibbage commented on GitHub (Feb 14, 2023):

I'm somewhat comfortable. I can open a shell in the Bookstack-DB container and run mysql commands. Been a while, but let's go for it!

By the way, thanks so much for the help :)

@MrGibbage commented on GitHub (Feb 14, 2023): I'm somewhat comfortable. I can open a shell in the Bookstack-DB container and run mysql commands. Been a while, but let's go for it! By the way, thanks so much for the help :)
Author
Owner

@ssddanbrown commented on GitHub (Feb 14, 2023):

Okay, before anything backup/snapshot all data/volumes since this is potentially dangerous.

We'll look to re-create the columns that the migration system expects.
Before running the below, make sure the bookstack app container has been stopped.

# Set the bookstack database as the active database.
# Change this to be the database name
use bookstack;

# Add back in the expected column
# Run these one-at-a-time.
# You may get a duplicate column warning, that's fine, just move onto the next.
ALTER TABLE pages add column restricted tinyint default 0;
ALTER TABLE chapters add column restricted tinyint default 0;
ALTER TABLE books add column restricted tinyint default 0;
ALTER TABLE bookshelves add column restricted tinyint default 0;

Once these are done, re-start the bookstack container, and be sure to record any log messages on first run (First run is vital to get the right detail if there are any other errors).
Hopefully you'll see a bunch of migration messages be logged after which things will be back running as normal.

@ssddanbrown commented on GitHub (Feb 14, 2023): Okay, before anything backup/snapshot all data/volumes since this is potentially dangerous. We'll look to re-create the columns that the migration system expects. Before running the below, make sure the bookstack app container has been stopped. ```sql # Set the bookstack database as the active database. # Change this to be the database name use bookstack; # Add back in the expected column # Run these one-at-a-time. # You may get a duplicate column warning, that's fine, just move onto the next. ALTER TABLE pages add column restricted tinyint default 0; ALTER TABLE chapters add column restricted tinyint default 0; ALTER TABLE books add column restricted tinyint default 0; ALTER TABLE bookshelves add column restricted tinyint default 0; ``` Once these are done, re-start the bookstack container, and be sure to record any log messages on first run (First run is vital to get the right detail if there are any other errors). Hopefully you'll see a bunch of migration messages be logged after which things will be back running as normal.
Author
Owner

@MrGibbage commented on GitHub (Feb 14, 2023):

That was easy! Worked perfectly. Thanks!

@MrGibbage commented on GitHub (Feb 14, 2023): That was easy! Worked perfectly. Thanks!
Author
Owner

@ssddanbrown commented on GitHub (Feb 14, 2023):

Great to hear!

@ssddanbrown commented on GitHub (Feb 14, 2023): Great to hear!
Author
Owner

@RandomUser0815 commented on GitHub (Jul 8, 2024):

@ssddanbrown In my case I had the same error, after installing Bookstack (latest) from scratch and restoring an older Bookstack v.22.09 database. I was able to fix it, by running the here mentioned command "php artisan migrate". Then it complained, that a table "watches" already existed. After I deleted it, I could successfully run the command, and start using bookstack.

https://laravel.com/docs/11.x/migrations

It would make sense to put that into the FAQ, don't yout think so too?

@RandomUser0815 commented on GitHub (Jul 8, 2024): @ssddanbrown In my case I had the same error, after installing Bookstack (latest) from scratch and restoring an older Bookstack v.22.09 database. I was able to fix it, by running the here mentioned command "php artisan migrate". Then it complained, that a table "watches" already existed. After I deleted it, I could successfully run the command, and start using bookstack. https://laravel.com/docs/11.x/migrations It would make sense to put that into the FAQ, don't yout think so too?
Author
Owner

@ssddanbrown commented on GitHub (Jul 8, 2024):

@RandomUser0815

It would make sense to put that into the FAQ, don't yout think so too?

No, you'd only come across this if something else has gone wrong before, and how it is addressed can be specific to the underlying issue otherwise you can cause more problems.

after installing Bookstack (latest) from scratch and restoring an older Bookstack v.22.09 database. [...] Then it complained, that a table "watches" already existed. After I deleted it, I could successfully run the command

You should not restore an old database into an existing/newer install. You should restore into an empty database then migrate, otherwise you may come across other issues to address (like you already did with the watches table).

@ssddanbrown commented on GitHub (Jul 8, 2024): @RandomUser0815 > It would make sense to put that into the FAQ, don't yout think so too? No, you'd only come across this if something else has gone wrong before, and how it is addressed can be specific to the underlying issue otherwise you can cause more problems. > after installing Bookstack (latest) from scratch and restoring an older Bookstack v.22.09 database. [...] Then it complained, that a table "watches" already existed. After I deleted it, I could successfully run the command You should not restore an old database into an existing/newer install. You should restore into an empty database then migrate, otherwise you may come across other issues to address (like you already did with the `watches` table).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#3507