Unable to upgrade to 1.22.x, ER_CANNOT_ADD_FOREIGN on table posts_authors
See original GitHub issueIssue Summary
A very similar problem to the one described at #9539 (definitely related to #9426), but this time with MySQL database and Linux as host OS (running Ghost as a Docker container). Trying to upgrade Ghost 1.21.x to Ghost 1.22.x will result on a database migration error.
[22:35:20] Running database migrations [started]
[22:35:33] Running database migrations [failed]
[22:35:33] The database migration in Ghost encountered an error.
A ProcessError occurred.
Message: The database migration in Ghost encountered an error.
Help: https://docs.ghost.org/v1/docs/troubleshooting#section-general-update-error
Suggestion: ghost update --rollback
--------------- stderr ---------------
[2018-05-01 22:35:33] ERROR
NAME: MigrationScriptError
CODE: ER_CANNOT_ADD_FOREIGN
MESSAGE: alter table 'posts_authors' add constraint 'posts_authors_post_id_foreign' foreign key ('post_id') references 'posts' ('id') - ER_CANNOT_ADD_FOREIGN: Cannot add foreign key constraint
Steps to Reproduce
- Run
ghost update -V
on a version 1.21.x blog. In this case it was version 1.21.2. - Error will show up.
I also tried to run knex-migrator
manually to get more detail about why the problem is happening and it looks like the database table post_authors
gets created and immediately deleted, so when the ALTER TABLE
query is sent, there is actually no table where it could be applied. I’m attaching the knex log to this issue.
Technical details:
Debug Information: OS: linux, v4.13.0-1011-azure Node Version: v6.13.0 Ghost-CLI Version: 1.7.2 Ghost version: 1.21.2 Database: MySQL 5.7 Environment: production Command: ‘ghost update -V’
Logs: ghost-cli-debug-2018-05-01T22_35_33_311Z.log knex-migrator.log
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Thank you @kirrg001 for the additional help offer, but I am not able to hand over the whole database, even if I know it is just for testing and bug hunting purposes 😃
I will try again in next upgrade with
ghost-cli
to see if I have the problem again.knex-migrator
worked as expected.@cmilanf I tried to reproduce, but no luck. Worked for me. Do you mind sending me your backup
/home/site/wwwroot/data/1.ghost.2018-05-02.json
to kate@ghost.org? I will delete your JSON file after testing. Maybe you have a specific data set which has caused this problem.