question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to upgrade to 1.22.x, ER_CANNOT_ADD_FOREIGN on table posts_authors

See original GitHub issue

Issue 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

  1. Run ghost update -V on a version 1.21.x blog. In this case it was version 1.21.2.
  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:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cmilanfcommented, May 2, 2018

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.

0reactions
kirrg001commented, May 2, 2018

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading from 1.21.X to 1.22.2 crashes api-server/etcd #12662
We had to downgrade to 1.20.7 from 1.22.2 and remove the command.json files from s3 that were still there from the failed upgrade...
Read more >
Upgrade an Azure Kubernetes Service (AKS) cluster
Learn how to upgrade an Azure Kubernetes Service (AKS) cluster to get the latest features and security updates.
Read more >
Upgrading kubeadm clusters - Kubernetes
This command checks that your cluster can be upgraded, and fetches the versions you can upgrade to. It also shows a table with...
Read more >
Will That Kubernetes v1.22 Upgrade Break My Application?
Lets first understand if your infrastructure-as-code manifests and helm charts need to be updated for the move to Kubernetes 1.22. Here are some ......
Read more >
Welcome to my upgrade guide to EKS version 1.22 | Datree.io
Previously they were deprecated, now they are outright REMOVED, so any workload trying to run using those removed versions will simply fail to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found