ERROR alter table members_cancel_events

Hello,

When I try to update my ghost instances from ghost:4.37.0 to ghost:4.48.5, I encounter the following problem:

- Inspecting operating system
[2022-10-05 12:13:44] INFO Ghost is running in production...
[2022-10-05 12:13:44] INFO Your site is now available on https://www.name.fr/blog/
[2022-10-05 12:13:44] INFO Ctrl+C to shut down
[2022-10-05 12:13:44] INFO Ghost server started in 0.814s
[2022-10-05 12:13:45] WARN Database state requires migration.
[2022-10-05 12:13:45] INFO Creating database backup
[2022-10-05 12:13:46] INFO Database backup written to: /bitnami/ghost/content/data/name.ghost.2022-10-05-12-13-45.json
[2022-10-05 12:13:46] INFO Running migrations.
[2022-10-05 12:13:46] INFO Adding products.visibility column
[2022-10-05 12:13:46] WARN Removing products.visible column - skipping as table is correct
[2022-10-05 12:13:46] WARN portal_plans does not include "free" - skipping migration
[2022-10-05 12:13:46] INFO Updating 2 products to visible, 609663e29a64140001b41205,62103d5867e3a200632ec229
[2022-10-05 12:13:46] INFO Adding table: members_cancel_events
[2022-10-05 12:13:46] INFO Rolling back: alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Can't create table `public_x`.`members_cancel_events` (errno: 150 "Foreign key constraint is incorrectly formed").
[2022-10-05 12:13:46] INFO Dropping table: members_cancel_events
[2022-10-05 12:13:46] INFO Updating portal_products to ["609663e29a64140001b41205","62103d5867e3a200632ec229"]
[2022-10-05 12:13:46] INFO Updating portal_plans to ["monthly","yearly"]
[2022-10-05 12:13:46] INFO Removing products.visibility column
[2022-10-05 12:13:46] WARN Removing products.visible column - skipping as table is correct
[2022-10-05 12:13:46] INFO Rollback was successful.
[2022-10-05 12:13:46] ERROR alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Can't create table `public_x`.`members_cancel_events` (errno: 150 "Foreign key constraint is incorrectly formed")

alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Can't create table `public_x`.`members_cancel_events` (errno: 150 "Foreign key constraint is incorrectly formed")

{"config":{"transaction":false},"name":"2022-03-07-14-37-add-members-cancel-events-table.js"}
"Error occurred while executing the following migration: 2022-03-07-14-37-add-members-cancel-events-table.js"

Error ID:
    300

Error Code: 
    ER_CANT_CREATE_TABLE

----------------------------------------

MigrationScriptError: alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Can't create table `public_x`.`members_cancel_events` (errno: 150 "Foreign key constraint is incorrectly formed")
    at DatabaseStateManager.makeReady (/opt/bitnami/ghost/versions/4.48.5/core/server/data/db/state-manager.js:95:32)
    at MigrationScriptError.KnexMigrateError (/opt/bitnami/ghost/versions/4.48.5/node_modules/knex-migrator/lib/errors.js:7:26)
    at new MigrationScriptError (/opt/bitnami/ghost/versions/4.48.5/node_modules/knex-migrator/lib/errors.js:25:26)
    at /opt/bitnami/ghost/versions/4.48.5/node_modules/knex-migrator/lib/index.js:1032:19
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Error: alter table `members_cancel_events` add constraint `members_cancel_events_member_id_foreign` foreign key (`member_id`) references `members` (`id`) on delete CASCADE - Can't create table `public_x`.`members_cancel_events` (errno: 150 "Foreign key constraint is incorrectly formed")
    at Packet.asError (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/packets/packet.js:728:17)
    at Query.execute (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/commands/command.js:29:26)
    at Connection.handlePacket (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/connection.js:456:32)
    at PacketParser.onPacket (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/connection.js:85:12)
    at PacketParser.executeStart (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/packet_parser.js:75:16)
    at Socket.<anonymous> (/opt/bitnami/ghost/versions/4.48.5/node_modules/mysql2/lib/connection.js:92:25)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)

[2022-10-05 12:13:46] WARN Ghost is shutting down
[2022-10-05 12:13:46] WARN Ghost has shut down
[2022-10-05 12:13:46] WARN Your site is now offline
[2022-10-05 12:13:46] WARN Ghost was running for a few seconds

Same with trying to upgrade 4.36.1 from 4.32.3

Error logs :

ghost 14:35:58.82 
ghost 14:35:58.82 Welcome to the Bitnami ghost container
ghost 14:35:58.82 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-ghost
ghost 14:35:58.83 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-ghost/issues
ghost 14:35:58.83 
ghost 14:35:58.83 INFO  ==> Configuring libnss_wrapper
ghost 14:35:58.86 INFO  ==> Validating settings in MYSQL_CLIENT_* env vars
ghost 14:35:58.97 WARN  ==> You set the environment variable ALLOW_EMPTY_PASSWORD=yes. For safety reasons, do not use this flag in a production environment.
ghost 14:35:58.98 INFO  ==> Restoring persisted Ghost installation
ghost 14:35:59.06 INFO  ==> Trying to connect to the database server
ghost 14:35:59.17 INFO  ==> ** Ghost setup finished! **

ghost 14:35:59.26 INFO  ==> ** Starting Ghost **
- Inspecting operating system
[2022-10-05 12:36:01] INFO Ghost is running in production...
[2022-10-05 12:36:01] INFO Your site is now available on https://www.y.com/
[2022-10-05 12:36:01] INFO Ctrl+C to shut down
[2022-10-05 12:36:01] INFO Ghost server started in 0.889s
[2022-10-05 12:36:02] WARN Database state requires migration.
[2022-10-05 12:36:03] INFO Creating database backup
[2022-10-05 12:36:03] INFO Database backup written to: /bitnami/ghost/content/data/marius-aurenti.ghost.2022-10-05-12-36-03.json
[2022-10-05 12:36:03] INFO Running migrations.
[2022-10-05 12:36:03] INFO Adding products.type column
[2022-10-05 12:36:03] INFO Adding tier "Free"
[2022-10-05 12:36:03] INFO Looking for duplicate offer redemptions.
[2022-10-05 12:36:03] INFO No duplicate offer redemptions found.
[2022-10-05 12:36:03] INFO Adding products.active column
[2022-10-05 12:36:03] INFO Adding products.welcome_page_url column
[2022-10-05 12:36:03] INFO Adding table: posts_products
[2022-10-05 12:36:04] INFO Rolling back: alter table `posts_products` add constraint `posts_products_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete CASCADE - ER_CANT_CREATE_TABLE: Can't create table `public_y`.`posts_products` (errno: 150 "Foreign key constraint is incorrectly formed").
[2022-10-05 12:36:04] INFO Dropping table: posts_products
[2022-10-05 12:36:04] INFO Removing products.welcome_page_url column
[2022-10-05 12:36:04] INFO Removing products.active column
[2022-10-05 12:36:04] WARN Not recreating duplicate offer redemptions
[2022-10-05 12:36:04] INFO Removing free tier
[2022-10-05 12:36:04] INFO Removing products.type column
[2022-10-05 12:36:04] INFO Rollback was successful.
[2022-10-05 12:36:04] ERROR alter table `posts_products` add constraint `posts_products_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete CASCADE - ER_CANT_CREATE_TABLE: Can't create table `public_y`.`posts_products` (errno: 150 "Foreign key constraint is incorrectly formed")

alter table `posts_products` add constraint `posts_products_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete CASCADE - ER_CANT_CREATE_TABLE: Can't create table `public_y`.`posts_products` (errno: 150 "Foreign key constraint is incorrectly formed")

{"config":{"transaction":false},"name":"2022-01-20-05-55-add-post-products-table.js"}
"Error occurred while executing the following migration: 2022-01-20-05-55-add-post-products-table.js"

Error ID:
    300

Error Code: 
    ER_CANT_CREATE_TABLE

----------------------------------------

MigrationScriptError: alter table `posts_products` add constraint `posts_products_post_id_foreign` foreign key (`post_id`) references `posts` (`id`) on delete CASCADE - ER_CANT_CREATE_TABLE: Can't create table `public_y`.`posts_products` (errno: 150 "Foreign key constraint is incorrectly formed")
    at DatabaseStateManager.makeReady (/opt/bitnami/ghost/versions/4.37.0/core/server/data/db/state-manager.js:95:32)
    at MigrationScriptError.KnexMigrateError (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/lib/errors.js:7:26)
    at new MigrationScriptError (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/lib/errors.js:25:26)
    at /opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/lib/index.js:1032:19
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Error: ER_CANT_CREATE_TABLE: Can't create table `public_y`.`posts_products` (errno: 150 "Foreign key constraint is incorrectly formed")
    at Query.Sequence._packetToError (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Query.ErrorPacket (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
    at Protocol._parsePacket (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
    at Socket.Readable.push (internal/streams/readable.js:206:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
    --------------------
    at Protocol._enqueue (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Connection.query (/opt/bitnami/ghost/versions/4.37.0/node_modules/mysql/lib/Connection.js:198:25)
    at /opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/dialects/mysql/index.js:134:18
    at new Promise (<anonymous>)
    at Client_MySQL._query (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/dialects/mysql/index.js:128:12)
    at Client_MySQL.query (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/client.js:168:17)
    at Runner.query (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/runner.js:151:36)
    at Runner.queryArray (/opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/runner.js:248:31)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /opt/bitnami/ghost/versions/4.37.0/node_modules/knex-migrator/node_modules/knex/lib/runner.js:277:18
    at async Object.up (/opt/bitnami/ghost/versions/4.37.0/core/server/data/migrations/utils.js:257:13)

[2022-10-05 12:36:04] WARN Ghost is shutting down
[2022-10-05 12:36:04] WARN Ghost has shut down
[2022-10-05 12:36:04] WARN Your site is now offline
[2022-10-05 12:36:04] WARN Ghost was running for a few seconds

It looks like you’re running MariaDB, which isn’t a supported database, any changes to Ghost, including upstream changes, will not have been tested.

I suspect this is the result of a mismatch of collation on the tables.

Hello,

Thanks for your feedback,

I just came back on the ghost update topics, sorry for being long.

Here is the information about my database server :

mysql> show variables like '%collation_connection%';
+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_general_ci |
+----------------------+--------------------+
1 row in set (0,03 sec)

mysql> SELECT @@GLOBAL.sql_mode;
+----------------------------------------------------------------------------------------------------------------------------------------------+
| @@GLOBAL.sql_mode                                                                                                                            |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+----------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,04 sec)

My docker image for the mariadb database :

mariadb-galera:10.6.7-debian-10-r7

As mentioned earlier, Ghost V5 requires MySQL; the site will break with MariaDB.

1 Like