BookStack icon indicating copy to clipboard operation
BookStack copied to clipboard

092941_create_references_table fail

Open dkauper opened this issue 3 years ago • 11 comments

Attempted Debugging

  • [X] I have read the debugging page

Searched GitHub Issues

  • [X] I have searched GitHub for the issue.

Describe the Scenario

Using linuxserver.io docker in unRaid. Needed to restore a backup of docker.img and encountered the above fail after logging into bookstack but I'm presented with a blank white browser window. The following is the log entry below

Any suggestions for how to fix? The database seems intact...

Exact BookStack Version

latest stable

Log Content

text  error  warn  system  array  login  

[migrations] started
[migrations] 01-nginx-site-confs-default: skipped
[migrations] 02-default-location: skipped
[migrations] done
───────────────────────────────────────

      ██╗     ███████╗██╗ ██████╗ 
      ██║     ██╔════╝██║██╔═══██╗
      ██║     ███████╗██║██║   ██║
      ██║     ╚════██║██║██║   ██║      
      ███████╗███████║██║╚██████╔╝
      ╚══════╝╚══════╝╚═╝ ╚═════╝ 

   Brought to you by linuxserver.io
───────────────────────────────────────

To support LSIO projects visit:
https://www.linuxserver.io/donate/

───────────────────────────────────────
GID/UID
───────────────────────────────────────

User UID:    99
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

   INFO  Running migrations.  

  2022_08_17_092941_create_references_table ......................... 4ms FAIL

   Illuminate\Database\QueryException 

  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'references' already exists (SQL: create table `references` (`id` bigint unsigned not null auto_increment primary key, `from_id` int unsigned not null, `from_type` varchar(25) not null, `to_id` int unsigned not null, `to_type` varchar(25) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760
    756▕         // If an exception occurs when attempting to run a query, we'll format the error
    757▕         // message to include the bindings with SQL, which will make this exception a
    758▕         // lot more helpful to the developer instead of just the database's errors.
    759▕         catch (Exception $e) {
  ➜ 760▕             throw new QueryException(
    761▕                 $query, $this->prepareBindings($bindings), $e
    762▕             );
    763▕         }
    764▕     }

      +9 vendor frames 
  10  /app/www/database/migrations/2022_08_17_092941_create_references_table.php:22
      Illuminate\Support\Facades\Facade::__callStatic()

      +25 vendor frames 
  36  /app/www/artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
[custom-init] No custom files found, skipping...
[ls.io-init] done.

PHP Version

No response

Hosting Environment

linuxserver bookstack docker on unRaid server

dkauper avatar Mar 17 '23 15:03 dkauper

Needed to restore a backup of docker.img

What exactly do you mean by this? If there's been a restore I'll need to understand the exact steps taken to understand the current state of things.

ssddanbrown avatar Mar 17 '23 16:03 ssddanbrown

The docker.img file on unRaid became corrupted (not an unusual occurrence on unRaid, unfortunately). I keep a weekly backup of the appdata share and can fairly easily reinstate all the docker images on the unRaid server after such a corruption. This time, however, while all the other docker images restored and running properly, bookstack presented with this odd result. I'm able to pass through the login screen, as usual, but the resulting web page is blank. Does the above log entry provide any clue as to what to fix?

Thank you for your response, by the way.

dkauper avatar Mar 17 '23 17:03 dkauper

Does the above log entry provide any clue as to what to fix?

It does but the problem is that it doesn't show how you've gotten into that state, which may affect things. There's no visibility on what is the cause of the problem. I can only guess you were running an older version of BookStack before (about July of 2022) and then something is not going wrong as the image tries to auto-migrate your database for the latest version of BookStack.

  • At any point, have you manually restored data into the MySQL/Mariadb database?
  • Are you familiar with accessing and managing the mysql database that's (presumably) also running in a container?
  • If not, do you have access to run docker exec commands in your environment?

ssddanbrown avatar Mar 17 '23 20:03 ssddanbrown

At any point, have you manually restored data into the MySQL/Mariadb database? No. Are you familiar with accessing and managing the mysql database that's (presumably) also running in a container? Yes, I am. I use adminer to access the mariadb database. If not, do you have access to run docker exec commands in your environment? I do have access to run docker exec command in the unRaid environment.

dkauper avatar Mar 17 '23 22:03 dkauper

Okay, since you have access to the database, access you bookstack database, find the references table, check if it has contents. If it has any rows stop and report back. Otherwise, drop the table.

After dropping, restart the bookstack container and watch the logs on first start-up. It might start working but if something goes wrong it's really important we see the first set of log messages.

ssddanbrown avatar Mar 18 '23 01:03 ssddanbrown

Hi Dan,

The references table had no entries so I dropped it as you advised. On restart, the log seems identical to the one I sent originally:

User UID: 99 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

INFO Running migrations.

2022_08_17_092941_create_references_table ........................ 59ms FAIL

Illuminate\Database\QueryException

SQLSTATE[HY000]: General error: 1005 Can't create table bookstack.references (errno: 184 "Tablespace already exists") (SQL: create table references (id bigint unsigned not null auto_increment primary key, from_id int unsigned not null, from_type varchar(25) not null, to_id int unsigned not null, to_type varchar(25) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

at /app/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760 756▕ // If an exception occurs when attempting to run a query, we'll format the error 757▕ // message to include the bindings with SQL, which will make this exception a 758▕ // lot more helpful to the developer instead of just the database's errors. 759▕ catch (Exception $e) { ➜ 760▕ throw new QueryException( 761▕ $query, $this->prepareBindings($bindings), $e 762▕ ); 763▕ } 764▕ }

  +9 vendor frames 

10 /app/www/database/migrations/2022_08_17_092941_create_references_table.php:22 Illuminate\Support\Facades\Facade::__callStatic()

  +25 vendor frames 

36 /app/www/artisan:37 Illuminate\Foundation\Console\Kernel::handle() [custom-init] No custom files found, skipping... [ls.io-init] done.

On Mar 17, 2023, at 6:25 PM, Dan Brown @.***> wrote:

Okay, since you have access to the database, access you bookstack database, find the references table, check if it has contents. If it has any rows stop and report back. Otherwise, drop the table.

After dropping, restart the bookstack container and watch the logs on first start-up. It might start working but if something goes wrong it's really important we see the first set of log messages.

— Reply to this email directly, view it on GitHub https://github.com/BookStackApp/BookStack/issues/4106#issuecomment-1474562585, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXSB6CF7F3XJ36AEYLCNKS3W4UFIDANCNFSM6AAAAAAV6VZWJA. You are receiving this because you authored the thread.

dkauper avatar Mar 18 '23 02:03 dkauper

The error is slightly different now, Even though you dropped the table the tablespace still exists. How did you drop the table?

I've never dealt with this scenario before, but looking online, you could try to delete the references.* files from within the <db_volume_mount>/databases/<database_name> folder but make sure you've double-backed-up everything first.

Not really sure how you get to this scenario, This feels similar to issues I've seen before with filesystem-specific issues (ZFS on LXC) so wonder if the database is sensitive to the unraid-backed storage.

ssddanbrown avatar Mar 18 '23 12:03 ssddanbrown

That did it! I deleted the references.idb file in addition to dropping the references table from the db and the connection between bookstack and the database is now made properly. You not only helped me solve this problem but you gave me a better understanding about solving similar problems in the future. Thank you very much Dan!

Doron Kauper

On Mar 18, 2023, at 5:58 AM, Dan Brown @.***> wrote:

The error is slightly different now, Even though you dropped the table the tablespace still exists. How did you drop the table?

I've never dealt with this scenario before, but looking online, you could try to delete the references.* files from within the <db_volume_mount>/databases/<database_name> folder but make sure you've double-backed-up everything first.

Not really sure how you get to this scenario, This feels similar to issues I've seen before with filesystem-specific issues (ZFS on LXC) so wonder if the database is sensitive to the unraid-backed storage.

— Reply to this email directly, view it on GitHub https://github.com/BookStackApp/BookStack/issues/4106#issuecomment-1474845259, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXSB6CEYEK2PWWFUUVDOJNTW4WWPBANCNFSM6AAAAAAV6VZWJA. You are receiving this because you authored the thread.

dkauper avatar Mar 18 '23 15:03 dkauper

Problem now solved. Thank you Dan. I dropped the references table from the db and also deleted the references.idb file from the file system.

dkauper avatar Mar 18 '23 15:03 dkauper

Happy to hear things are now working! By the way, if you happen to auto-upgrade your containers in any way can you just confirm back how you do so (For example, something like watchtower). I've been noticing issues with such tools so just trying to track their impact.

ssddanbrown avatar Mar 18 '23 15:03 ssddanbrown

I’m using a unRaid Community Applications appdata backup module named Appdata Backup/Restore V2 by Andrew Zawadski (the forked version by Robin Kluth).

On Mar 18, 2023, at 8:41 AM, Dan Brown @.***> wrote:

Happy to hear things are now working! By the way, if you happen to auto-upgrade your containers in any way can you just confirm back how you do so (For example, something like watchtower). I've been noticing issues with such tools so just trying to track their impact.

— Reply to this email directly, view it on GitHub https://github.com/BookStackApp/BookStack/issues/4106#issuecomment-1474881431, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXSB6CF6JNQXQM3G47LNDXTW4XJRPANCNFSM6AAAAAAV6VZWJA. You are receiving this because you modified the open/close state.

dkauper avatar Mar 18 '23 15:03 dkauper