Skip to content

Migration error from upgrade 25.7.3 to 25.12.8 #6052

@RogerSik

Description

@RogerSik

Attempted Debugging

  • I have read the debugging page

Searched GitHub Issues

  • I have searched GitHub for the issue.

Describe the Scenario

When upgrading from 25.7.3 to 25.12.8 follow error occurs:

wait-for-db: waiting for bookstack-db-stg.bookstack-stg.svc.cluster.local:3306
wait-for-db: done
Starting Migration...

   INFO  Running migrations.

  2025_09_15_134751_update_entity_relation_columns ............... 5.35ms FAIL

In Connection.php line 838:

  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP FOREIGN
  KEY `bookshelves_books_book_id_foreign`; check that it exists (Connection:
  mysql, Host: bookstack-db-stg.bookstack-stg.svc.cluster.local, Port: 3306,
  Database: app, SQL: alter table `bookshelves_books` drop foreign key `books
  helves_books_book_id_foreign`)


In Connection.php line 584:

  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP FOREIGN
  KEY `bookshelves_books_book_id_foreign`; check that it exists

A downgrade to 25.7.3 to is possible. But I'm not sure how to fix these errors to be able to upgrade to 25.12.8

I could partly fix it thanks to #6046

Altered bookshelves_books.book_id bigint into int
Altered bookshelves_books.bookshelf_id bigint into int
Add constraint between bookshelves_books.book_id and books.id
Add constraint between bookshelves_books.bookshelf_id and bookshelves.id

Which is in code

-- Change column types  
ALTER TABLE bookshelves_books  
MODIFY book_id INT UNSIGNED;  
  
ALTER TABLE bookshelves_books  
MODIFY bookshelf_id INT UNSIGNED;  
  
-- Add foreign key constraints  
ALTER TABLE bookshelves_books  
ADD CONSTRAINT bookshelves_books_book_id_foreign  
FOREIGN KEY (book_id) REFERENCES books(id)  
ON DELETE CASCADE;  
  
ALTER TABLE bookshelves_books  
ADD CONSTRAINT bookshelves_books_bookshelf_id_foreign  
FOREIGN KEY (bookshelf_id) REFERENCES bookshelves(id)  
ON DELETE CASCADE;

It fixed that the migration was running successful and bookstack is again accessible. But when accessing / editing of pages I see only older version. A workaround is to get into the Bookstack page revision and restore the newest version.

Image

The Page revisions:

Image

Kindly asking if somehow knows a solution for it. I'm trying digging here and if I find a solution I will post it here.

Exact BookStack Version

25.7.3

Log Content


Hosting Environment

Ubuntu 24.04 with rke2 1.33.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions