{"action":"opened","issue":{"url":"https://api.github.com/repos/TryGhost/Ghost/issues/9613","repository_url":"https://api.github.com/repos/TryGhost/Ghost","labels_url":"https://api.github.com/repos/TryGhost/Ghost/issues/9613/labels{/name}","comments_url":"https://api.github.com/repos/TryGhost/Ghost/issues/9613/comments","events_url":"https://api.github.com/repos/TryGhost/Ghost/issues/9613/events","html_url":"https://github.com/TryGhost/Ghost/issues/9613","id":319354774,"number":9613,"title":"Unable to upgrade to 1.22.x, ER_CANNOT_ADD_FOREIGN on table posts_authors","user":{"login":"cmilanf","id":20147259,"avatar_url":"https://avatars3.githubusercontent.com/u/20147259?v=4","gravatar_id":"","url":"https://api.github.com/users/cmilanf","html_url":"https://github.com/cmilanf","followers_url":"https://api.github.com/users/cmilanf/followers","following_url":"https://api.github.com/users/cmilanf/following{/other_user}","gists_url":"https://api.github.com/users/cmilanf/gists{/gist_id}","starred_url":"https://api.github.com/users/cmilanf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmilanf/subscriptions","organizations_url":"https://api.github.com/users/cmilanf/orgs","repos_url":"https://api.github.com/users/cmilanf/repos","events_url":"https://api.github.com/users/cmilanf/events{/privacy}","received_events_url":"https://api.github.com/users/cmilanf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-01T22:55:29Z","updated_at":"2018-05-01T22:55:29Z","closed_at":null,"author_association":"NONE","body":"### Issue Summary\r\n\r\nA 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.\r\n\r\n```\r\n[22:35:20] Running database migrations [started]\r\n[22:35:33] Running database migrations [failed]\r\n[22:35:33] The database migration in Ghost encountered an error.\r\nA ProcessError occurred.\r\n\r\nMessage: The database migration in Ghost encountered an error.\r\nHelp: https://docs.ghost.org/v1/docs/troubleshooting#section-general-update-error\r\nSuggestion: ghost update --rollback\r\n--------------- stderr ---------------\r\n[2018-05-01 22:35:33] ERROR\r\n\r\nNAME: MigrationScriptError\r\nCODE: ER_CANNOT_ADD_FOREIGN\r\nMESSAGE: 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\r\n```\r\n\r\n### Steps to Reproduce\r\n\r\n1. Run `ghost update -V` on a version 1.21.x blog. In this case it was version 1.21.2.\r\n2. Error will show up.\r\n\r\nI 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.\r\n\r\n### Technical details:\r\nDebug Information:\r\n    OS: linux, v4.13.0-1011-azure\r\n    Node Version: v6.13.0\r\n    Ghost-CLI Version: 1.7.2\r\n    Ghost version: 1.21.2\r\n    Database: MySQL 5.7\r\n    Environment: production\r\n    Command: 'ghost update -V'\r\n\r\nLogs:\r\n[ghost-cli-debug-2018-05-01T22_35_33_311Z.log](https://github.com/TryGhost/Ghost/files/1965403/ghost-cli-debug-2018-05-01T22_35_33_311Z.log)\r\n[knex-migrator.log](https://github.com/TryGhost/Ghost/files/1965405/knex-migrator.log)\r\n"}}
{"actor":{"display_login":"cmilanf"}}