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.

Migration locked / migrations and migrations_lock are empty

See original GitHub issue

Versions:

  • Ghost: Docker Image: ghost:1.20.1-alpine
  • MySQL Docker Image: mysql:5.7.20

I am using docker image 1.20.1 with mysql as the DB connector. Blog was working fine, it got rescheduled to a new host and now its stuck in a migration error. I have tested the DB connection works from ghost host and that the tables exist.

 NAME: MigrationsAreLockedError
MESSAGE: Migrations are running at the moment. Please wait that the lock get`s released.
 level:normal
 Either the release was never released because of a e.g. died process or a parallel process is migrating at the moment.
If your database looks okay, you can manually release the lock by running `UPDATE migrations_lock set locked=0 where lock_key='km01';`.
MigrationsAreLockedError: Migrations are running at the moment. Please wait that the lock get`s released.
    at MigrationsAreLockedError.KnexMigrateError (/var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/errors.js:9:26)
    at new MigrationsAreLockedError (/var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/errors.js:40:26)
    at /var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/index.js:799:27
    at tryCatcher (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

The MySQL database has no entries in migrations_lock. When I enter the container and try to run the knex command with --force the error still persists.

Migrations table in mysql:

+----+-------------------------------+---------+----------------+
| id | name                          | version | currentVersion |
+----+-------------------------------+---------+----------------+
|  3 | 1-post-excerpt.js             | 1.3     | 1.19           |
|  4 | 1-codeinjection-post.js       | 1.4     | 1.19           |
|  5 | 1-og-twitter-post.js          | 1.5     | 1.19           |
|  6 | 1-add-backup-client.js        | 1.7     | 1.19           |
|  7 | 1-add-permissions-redirect.js | 1.9     | 1.19           |
|  8 | 1-custom-template-post.js     | 1.13    | 1.19           |
|  9 | 2-theme-permissions.js        | 1.13    | 1.19           |
| 10 | 1-add-webhooks-table.js       | 1.18    | 1.19           |
| 11 | 1-webhook-permissions.js      | 1.19    | 1.19           |
+----+-------------------------------+---------+----------------+
9 rows in set (0.00 sec)

Attemping to rollback:

bash-4.3# knex-migrator rollback --mgpath "$GHOST_INSTALL/current"
[2018-01-18 06:21:12] ERROR No migrations available to rollback. 

Output from DEBUG=* node current/index.js

  ghost:config         'users',
  ghost:config         'wp-admin',
  ghost:config         'wp-login' ],
  ghost:config      protected: [ 'ghost', 'rss', 'amp' ] },
  ghost:config   uploads: 
  ghost:config    { subscribers: { extensions: [Object], contentTypes: [Object] },
  ghost:config      images: { extensions: [Object], contentTypes: [Object] },
  ghost:config      icons: { extensions: [Object], contentTypes: [Object] },
  ghost:config      db: { extensions: [Object], contentTypes: [Object] },
  ghost:config      themes: { extensions: [Object], contentTypes: [Object] },
  ghost:config      redirects: { extensions: [Object], contentTypes: [Object] } },
  ghost:config   times: 
  ghost:config    { cannotScheduleAPostBeforeInMinutes: 2,
  ghost:config      publishAPostBySchedulerToleranceInMinutes: 2,
  ghost:config      getImageSizeTimeoutInMS: 5000 },
  ghost:config   maintenance: { enabled: false },
  ghost:config   env: 'production' } +78ms
  ghost:config config end +38ms
  ghost:services:url:cache adding url /blog/ +651ms
  ghost:services:url:cache adding url /blog/subscribe/ +1ms
  ghost:boot:index Required ghost +468ms
  express:application set "x-powered-by" to true +2ms
  express:application set "etag" to 'weak' +0ms
  express:application set "etag fn" to [Function: generateETag] +0ms
  express:application set "env" to 'production' +0ms
  express:application set "query parser" to 'extended' +1ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +0ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +0ms
  express:application set "trust proxy fn" to [Function: trustNone] +1ms
  express:application booting in production mode +0ms
  express:application set "view" to [Function: View] +0ms
  express:application set "views" to '/var/lib/ghost/views' +0ms
  express:application set "jsonp callback name" to 'callback' +0ms
  express:application set "view cache" to true +0ms
  ghost:boot:index Initialising Ghost +1ms
  ghost:boot:init Init Start... +0ms
  ghost:boot:init Default i18n done for core +5ms
  ghost:boot:init models done +28ms
  knex-migrator:index Ensure Lock Table. +5ms
  knex:client acquired connection from pool: __knexUid2 +0ms
  knex:query select * from information_schema.tables where table_name = ? and table_schema = database() +0ms
  knex:bindings [ 'migrations_lock' ] +0ms
  knex:client releasing connection to pool: __knexUid2 +17ms
  knex-migrator:index Ensure Field Length. +40ms
  knex:client acquired connection from pool: __knexUid3 +3ms
  knex:query select * from information_schema.tables where table_name = ? and table_schema = database() +16ms
  knex:bindings [ 'migrations' ] +16ms
  knex:client releasing connection to pool: __knexUid3 +4ms
  knex:client acquired connection from pool: __knexUid2 +0ms
  knex:query alter table `migrations` modify `name` varchar(120) not null, modify `version` varchar(70) not null +11ms
  knex:bindings [] +11ms
  knex:client releasing connection to pool: __knexUid2 +20ms
  knex-migrator:index Ensure Unique Index. +27ms
  knex:client acquired connection from pool: __knexUid3 +2ms
  knex:query select * from information_schema.tables where table_name = ? and table_schema = database() +15ms
  knex:bindings [ 'migrations' ] +15ms
  knex:client releasing connection to pool: __knexUid3 +1ms
  knex:client acquired connection from pool: __knexUid2 +1ms
  knex:query alter table `migrations` add unique `migrations_name_version_unique`(`name`, `version`) +4ms
  knex:bindings [] +4ms
  knex:client releasing connection to pool: __knexUid2 +6ms
  knex:client acquired connection from pool: __knexUid3 +2ms
  knex:query select * from `migrations_lock` where `lock_key` = ? +10ms
  knex:bindings [ 'km01' ] +10ms
  knex:client releasing connection to pool: __knexUid3 +6ms
  knex-migrator:index Destroy connection +18ms
  knex-migrator:index Destroyed connection +8ms
  ghost-query QUERY select * from `settings` +7ms
  knex:client acquired connection from pool: __knexUid1 +23ms
  knex:query select `settings`.* from `settings` where `settings`.`key` = ? limit ? +26ms
  knex:bindings [ 'databaseVersion', 1 ] +27ms
  knex:client releasing connection to pool: __knexUid1 +3ms
[2018-01-18 06:57:48] ERROR

NAME: MigrationsAreLockedError
MESSAGE: Migration lock was never released or currently a migration is running.

level:normal

If you are sure no migration is running, check your data and if your database is in a broken state, you could run `knex-migrator rollback`.
MigrationsAreLockedError: Migration lock was never released or currently a migration is running.
    at MigrationsAreLockedError.KnexMigrateError (/var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/errors.js:9:26)
    at new MigrationsAreLockedError (/var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/errors.js:40:26)
    at /var/lib/ghost/versions/1.20.1/node_modules/knex-migrator/lib/index.js:835:23
    at tryCatcher (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/var/lib/ghost/versions/1.20.1/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)

bash-4.3# 

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
qrpikecommented, Jan 18, 2018

Deleting the entire migrations and migrations_lock tables solved the issue.

1reaction
n-alex-whitecommented, Jan 17, 2019

Hi @kirrg001 - I’m seeing this problem when creating a fresh azure app service app, loading a ghost container. If I don’t try to map the content folders to the azure ‘home’ folder, all starts OK but I lose my data every time the app service shuffles things around internally.

If I attempt to map the ‘home’ folder to the content directory, I get this MigrationsAreLockedError

This is my docker compose file

version: '3.2'

services:

  ghost:
    image: ghost:2.2.4-alpine
    restart: always
    ports:
      - 80:2368
    volumes: 
      - ${WEBAPP_STORAGE_HOME}:/var/lib/ghost/content
Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling locks during database schema updates
To understand why the database may suffer when doing schema migrations, we must first understand the concept of locking.
Read more >
Mocha mysql knex before each fails: Can't take lock to run ...
Remove all rows in migrations_lock table and try again. Probably some migration has crashed and left lock in place.
Read more >
Migrations
The locks are saved in a table called " tableName _lock"; it has a column called is_locked that knex migrate:unlock sets to 0...
Read more >
Stop worrying about PostgreSQL locks in your Rails ...
In this article we will go through the most common pitfalls that could happen when migrating a database, and how, at Doctolib, ...
Read more >
Nginx-proxy-manager fails to start due to Migration table is ...
Can't take lock to run migrations: Migration table is already locked, ... all the rows = require(migrations lock table: migrations_lock,.
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