Error on upgrading to 0.31.3 #2031

Closed
opened 2026-02-05 02:38:10 +03:00 by OVERLORD · 8 comments
Owner

Originally created by @joe-eklund on GitHub (Jan 11, 2021).

Describe the bug
I am running version v0.30.5 and when I try to upgrade to v0.31.3 I get a 500 error. This is the error:

Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owned_by' in 'where clause' (SQL: select * from `activities` where (exists (select `id` from `joint_permissions` where joint_permissions.entity_id=activities.entity_id and joint_permissions.entity_type=activities.entity_type and `action` = view and `role_id` in (4) and (`has_permission` = 1 or (`has_permission_own` = 1 and `owned_by` = 2)))) order by `created_at` desc limit 10 offset 0)

I am hosting this in docker. So I figured I would try to run the migrations manually. I logged into my bookstack container, navigated to /var/www/html and ran php artisan migrate. The following error is outputed:

root@d811a18c591b:/var/www/html# php artisan migrate
**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes

Migrating: 2020_09_27_210528_create_deletions_table

   Illuminate\Database\QueryException  : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists (SQL: create table `deletions` (`id` int unsigned not null auto_increment primary key, `deleted_by` int not null, `deletable_type` varchar(100) not null, `deletable_id` int not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

  at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
    665|         // If an exception occurs when attempting to run a query, we'll format the error
    666|         // message to include the bindings with SQL, which will make this exception a
    667|         // lot more helpful to the developer instead of just the database's errors.
    668|         catch (Exception $e) {
  > 669|             throw new QueryException(
    670|                 $query, $this->prepareBindings($bindings), $e
    671|             );
    672|         }
    673|

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists")
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:131

  2   PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists")
      /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:129

  Please use the argument -v to see more details.

The above error is also displayed in my docker logs, so it seems bookstack tried to do it itself and failed with the same error.

Expected behavior
I can upgrade to the new version and everything loads.

Your Configuration (please complete the following information):

  • Exact BookStack Version (Found in settings): v0.31.3
  • PHP Version: 7.3.26
  • Hosting Method (Nginx/Apache/Docker): Docker

Additional context
For now I am running v0.30.5 and all is well. Any ideas on what I can do to upgrade would be much appreciated!

Originally created by @joe-eklund on GitHub (Jan 11, 2021). **Describe the bug** I am running version v0.30.5 and when I try to upgrade to v0.31.3 I get a 500 error. This is the error: ``` Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owned_by' in 'where clause' (SQL: select * from `activities` where (exists (select `id` from `joint_permissions` where joint_permissions.entity_id=activities.entity_id and joint_permissions.entity_type=activities.entity_type and `action` = view and `role_id` in (4) and (`has_permission` = 1 or (`has_permission_own` = 1 and `owned_by` = 2)))) order by `created_at` desc limit 10 offset 0) ``` I am hosting this in docker. So I figured I would try to run the migrations manually. I logged into my bookstack container, navigated to `/var/www/html` and ran `php artisan migrate`. The following error is outputed: ``` root@d811a18c591b:/var/www/html# php artisan migrate ************************************** * Application In Production! * ************************************** Do you really wish to run this command? (yes/no) [no]: > yes Migrating: 2020_09_27_210528_create_deletions_table Illuminate\Database\QueryException : SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists (SQL: create table `deletions` (`id` int unsigned not null auto_increment primary key, `deleted_by` int not null, `deletable_type` varchar(100) not null, `deletable_id` int not null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci') at /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make this exception a 667| // lot more helpful to the developer instead of just the database's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists") /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:131 2 PDOException::("SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'deletions' already exists") /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatement.php:129 Please use the argument -v to see more details. ``` The above error is also displayed in my docker logs, so it seems bookstack tried to do it itself and failed with the same error. **Expected behavior** I can upgrade to the new version and everything loads. **Your Configuration (please complete the following information):** - Exact BookStack Version (Found in settings): v0.31.3 - PHP Version: 7.3.26 - Hosting Method (Nginx/Apache/Docker): Docker **Additional context** For now I am running v0.30.5 and all is well. Any ideas on what I can do to upgrade would be much appreciated!
OVERLORD added the 🐕 Support label 2026-02-05 02:38:10 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Jan 16, 2021):

Hi @joe-eklund,

This is an odd migration for something to fail at, there's not much in there.
Be sure to take a couple of backups first, but you could try dropping the deletions table and then re-run the migration to see how far it progresses.

@ssddanbrown commented on GitHub (Jan 16, 2021): Hi @joe-eklund, This is an odd migration for something to fail at, there's not much in there. Be sure to take a couple of backups first, but you could try dropping the `deletions` table and then re-run the migration to see how far it progresses.
Author
Owner

@struppy commented on GitHub (Jan 17, 2021):

hi i have a same prob 👍 Migrating: 2020_08_04_111754_drop_joint_permissions_id

Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'id'; check that column/key exists (SQL: alter table joint_permissions drop id)

at /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connect ion.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make th is exception a
667| // lot more helpful to the developer instead of just the databa se's errors.
668| catch (Exception $e) {

669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|

Exception trace:

1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or acce ss violation: 1091 Can't DROP 'id'; check that column/key exists")
/var/www/bookstack/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatem ent.php:131

2 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1091 Ca n't DROP 'id'; check that column/key exists")
/var/www/bookstack/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatem ent.php:129

Please use the argument -v to see more details.

@struppy commented on GitHub (Jan 17, 2021): hi i have a same prob 👍 Migrating: 2020_08_04_111754_drop_joint_permissions_id Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'id'; check that column/key exists (SQL: alter table `joint_permissions` drop `id`) at /var/www/bookstack/vendor/laravel/framework/src/Illuminate/Database/Connect ion.php:669 665| // If an exception occurs when attempting to run a query, we'll format the error 666| // message to include the bindings with SQL, which will make th is exception a 667| // lot more helpful to the developer instead of just the databa se's errors. 668| catch (Exception $e) { > 669| throw new QueryException( 670| $query, $this->prepareBindings($bindings), $e 671| ); 672| } 673| Exception trace: 1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or acce ss violation: 1091 Can't DROP 'id'; check that column/key exists") /var/www/bookstack/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatem ent.php:131 2 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1091 Ca n't DROP 'id'; check that column/key exists") /var/www/bookstack/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOStatem ent.php:129 Please use the argument -v to see more details.
Author
Owner

@ssddanbrown commented on GitHub (Jan 17, 2021):

Hi @struppy,
Your issue is slightly different, Please view this GitHub issue for details on your particular problem: https://github.com/BookStackApp/BookStack/issues/2317

@ssddanbrown commented on GitHub (Jan 17, 2021): Hi @struppy, Your issue is slightly different, Please view this GitHub issue for details on your particular problem: https://github.com/BookStackApp/BookStack/issues/2317
Author
Owner

@struppy commented on GitHub (Jan 18, 2021):

Hi the sql commande : alter ignore table joint_permissions add primary
key joint_primary(role_id, entity_type, entity_id, action);

Provide an error :
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near 'ignore table joint_permissions add primary key
joint_primary(role_id, `ent' at line 1

my mysql version 5.7.32
Cordialement

*Didier STRUPP *

Le dim. 17 janv. 2021 à 12:40, Dan Brown notifications@github.com a
écrit :

Hi @struppy https://github.com/struppy,
Your issue is slightly different, Please view this GitHub issue for
details on your particular problem: #2317
https://github.com/BookStackApp/BookStack/issues/2317


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/BookStackApp/BookStack/issues/2473#issuecomment-761792518,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AEIIHPWM3TAY4YWUKPDK7SLS2LEBVANCNFSM4V45V7TQ
.

@struppy commented on GitHub (Jan 18, 2021): Hi the sql commande : alter ignore table `joint_permissions` add primary key `joint_primary`(`role_id`, `entity_type`, `entity_id`, `action`); Provide an error : ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ignore table `joint_permissions` add primary key `joint_primary`(`role_id`, `ent' at line 1 my mysql version 5.7.32 Cordialement *Didier STRUPP * Le dim. 17 janv. 2021 à 12:40, Dan Brown <notifications@github.com> a écrit : > Hi @struppy <https://github.com/struppy>, > Your issue is slightly different, Please view this GitHub issue for > details on your particular problem: #2317 > <https://github.com/BookStackApp/BookStack/issues/2317> > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <https://github.com/BookStackApp/BookStack/issues/2473#issuecomment-761792518>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AEIIHPWM3TAY4YWUKPDK7SLS2LEBVANCNFSM4V45V7TQ> > . >
Author
Owner

@struppy commented on GitHub (Feb 24, 2021):

Hi,

i have solved my issue,

Before upgrade i have paste this command on mysql database ( replace INGORE command déprécated on mysql 5.7.32)

use bookstack; # Rename to your own database.
alter table joint_permissions add column id int;
alter table joint_permissions ENGINE=InnoDB;

#####replace IGNORE Fonction####

CREATE TABLE joint_permissions_new LIKE joint_permissions;
ALTER TABLE joint_permissions_new add primary key joint_primary(role_id, entity_type, entity_id, action);
INSERT IGNORE INTO joint_permissions_new SELECT * FROM joint_permissions;
DROP TABLE joint_permissions;
RENAME TABLE joint_permissions_new TO joint_permissions;

alter table joint_permissions drop primary key;

i'm now on 0.31.6.

yes ! !

@struppy commented on GitHub (Feb 24, 2021): Hi, i have solved my issue, Before upgrade i have paste this command on mysql database ( replace INGORE command déprécated on mysql 5.7.32) use bookstack; # Rename to your own database. alter table joint_permissions add column id int; alter table joint_permissions ENGINE=InnoDB; #####replace IGNORE Fonction#### CREATE TABLE joint_permissions_new LIKE joint_permissions; ALTER TABLE joint_permissions_new add primary key `joint_primary`(`role_id`, `entity_type`, `entity_id`, `action`); INSERT IGNORE INTO joint_permissions_new SELECT * FROM joint_permissions; DROP TABLE joint_permissions; RENAME TABLE joint_permissions_new TO joint_permissions; alter table joint_permissions drop primary key; i'm now on 0.31.6. yes ! !
Author
Owner

@ssddanbrown commented on GitHub (Feb 25, 2021):

Thanks for confirming @struppy.

I'll go ahead and close this off since there's been no follow-up from the original issue creator.

@ssddanbrown commented on GitHub (Feb 25, 2021): Thanks for confirming @struppy. I'll go ahead and close this off since there's been no follow-up from the original issue creator.
Author
Owner

@thescottyq commented on GitHub (Mar 13, 2021):

@struppy

Your fix saved me! Thank you!

I had tried everything before I realised the IGNORE was deprecated in ALTER TABLE and was almost at the point of rolling the whole server back for another day

Thank you again!

@thescottyq commented on GitHub (Mar 13, 2021): @struppy Your fix saved me! Thank you! I had tried everything before I realised the IGNORE was deprecated in ALTER TABLE and was almost at the point of rolling the whole server back for another day Thank you again!
Author
Owner

@joe-eklund commented on GitHub (Jul 2, 2021):

I was able to finally get this working by doing the following:

  1. Follow @struppy instructions.
  2. Delete my deletions table file.
  3. Dropping the deletions table.
  4. Rerunning migrations.
@joe-eklund commented on GitHub (Jul 2, 2021): I was able to finally get this working by doing the following: 1. Follow @struppy instructions. 2. Delete my deletions table file. 3. Dropping the deletions table. 3. Rerunning migrations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2031