Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save iagopiimenta/403f098ace3fc1ab3f999767e96a64b7 to your computer and use it in GitHub Desktop.
Save iagopiimenta/403f098ace3fc1ab3f999767e96a64b7 to your computer and use it in GitHub Desktop.

Mysql2::Error: Specified key was too long; max key length is 767 bytes

You might get this error with InnoDB tables on MariaDB < 10.2.2, MySQL < 5.7. Although, this error might be also triggered on newer versions if you switch to COMPACT row format.

In the abovementioned releases the default InnoDB row format is COMPACT. With this format the maximum index prefix length is 767 bytes. The default character set is latin1, but if you use utf8mb4 encoding that restricts VARCHAR fields to up to 191 character (4 bytes per character). rails defaults to 255 characters for VARCHAR fields when creating tables. So, if you don't specify limit and add an index, you get the error.

Let's try to reproduce the issue:

docker-compose.yml:

version: '3'

services:
    app:
        build: .
        command: ./create-app.sh
        volumes:
            - ./create-app.sh:/create-app.sh
    db:
        image: mariadb:10.1
        environment:
            MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
            MYSQL_DATABASE: db1
        volumes:
            - db:/var/lib/mysql
            - ./charset.cnf:/etc/mysql/conf.d/charset.cnf

volumes:
    db:

Dockerfile:

FROM ruby:2.6-alpine
RUN apk add --no-cache build-base git tzdata nodejs yarn mariadb-dev wait4ports neovim

charset.cnf:

[mysqld]
character-set-server = utf8mb4

create-app.sh:

#!/bin/sh
set -eux
wait4ports tcp://db:3306
gem install rails -v 6.0.2.1
gem install bundler
rails new -d mysql app
cd app
bin/rails generate model post title:string:index
sed -Ei 's/\bhost: .*/host: db/' config/database.yml
sed -Ei 's/\bdatabase: .*/database: db1/' config/database.yml
sleep 100000000000
$ docker-compose down -v --rmi local
$ docker-compose pull
$ docker-compose build
$ docker-compose up -d

$ docker-compose exec app sh -c 'wait4ports tcp://db:3306 && cd app && bin/rails db:migrate'
== 20200114145346 CreatePosts: migrating ======================================
-- create_table(:posts)
   -> 0.0198s
-- add_index(:posts, :title)
rails aborted!
StandardError: An error has occurred, all later migrations canceled:

Mysql2::Error: Specified key was too long; max key length is 767 bytes
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:202:in `block (2 levels) in execute'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `bloc
k in permit_concurrent_loads'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yie
ld_shares'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `perm
it_concurrent_loads'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:201:in `block in execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:718:in `block (2 levels) in log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:717:in `block in log'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `
instrument'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:708:in `log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:200:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/mysql/database_stat
ements.rb:41:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:372:in `add_index'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:890:in `block in method_mi
ssing'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `block in say_with_
time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `say_with_time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:879:in `method_missing'
/app/db/migrate/20200114145346_create_posts.rb:8:in `change'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:828:in `exec_migration'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:812:in `block (2 levels) i
n migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:811:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection
_pool.rb:473:in `with_connection'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:810:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1001:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1311:in `block in execute_
migration_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1364:in `ddl_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1310:in `execute_migration
_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1282:in `block in migrate_
without_lock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `migrate_without_l
ock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1382:in `with_advisory_loc
k'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `up'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1036:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate
'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:86:in `block (3
 levels) in <main>'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `block (2
 levels) in <main>'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perfo
rm'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
require'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `re
gister'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `
require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `
require'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in requ
ire'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependen
cy'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
/app/bin/rails:9:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/app/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
ActiveRecord::StatementInvalid: Mysql2::Error: Specified key was too long; max key length is 767 byte
s
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:202:in `block (2 levels) in execute'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `bloc
k in permit_concurrent_loads'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yie
ld_shares'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `perm
it_concurrent_loads'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:201:in `block in execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:718:in `block (2 levels) in log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:717:in `block in log'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `
instrument'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:708:in `log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:200:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/mysql/database_stat
ements.rb:41:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:372:in `add_index'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:890:in `block in method_mi
ssing'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `block in say_with_
time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `say_with_time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:879:in `method_missing'
/app/db/migrate/20200114145346_create_posts.rb:8:in `change'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:828:in `exec_migration'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:812:in `block (2 levels) i
n migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:811:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection
_pool.rb:473:in `with_connection'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:810:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1001:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1311:in `block in execute_
migration_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1364:in `ddl_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1310:in `execute_migration
_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1282:in `block in migrate_
without_lock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `migrate_without_l
ock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1382:in `with_advisory_loc
k'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `up'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1036:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate
'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:86:in `block (3
 levels) in <main>'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `block (2
 levels) in <main>'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perfo
rm'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
require'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `re
gister'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `
require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `
require'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in requ
ire'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependen
cy'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
/app/bin/rails:9:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/app/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
Mysql2::Error: Specified key was too long; max key length is 767 bytes
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:202:in `block (2 levels) in execute'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:48:in `bloc
k in permit_concurrent_loads'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/concurrency/share_lock.rb:187:in `yie
ld_shares'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies/interlock.rb:47:in `perm
it_concurrent_loads'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:201:in `block in execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:718:in `block (2 levels) in log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:717:in `block in log'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/notifications/instrumenter.rb:24:in `
instrument'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_adapter.rb
:708:in `log'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:200:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/mysql/database_stat
ements.rb:41:in `execute'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract_mysql_adap
ter.rb:372:in `add_index'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:890:in `block in method_mi
ssing'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `block in say_with_
time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:858:in `say_with_time'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:879:in `method_missing'
/app/db/migrate/20200114145346_create_posts.rb:8:in `change'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:828:in `exec_migration'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:812:in `block (2 levels) i
n migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:811:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/connection_adapters/abstract/connection
_pool.rb:473:in `with_connection'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:810:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1001:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1311:in `block in execute_
migration_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1364:in `ddl_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1310:in `execute_migration
_in_transaction'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1282:in `block in migrate_
without_lock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1281:in `migrate_without_l
ock'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `block in migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1382:in `with_advisory_loc
k'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1229:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1061:in `up'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/migration.rb:1036:in `migrate'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/tasks/database_tasks.rb:238:in `migrate
'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:86:in `block (3
 levels) in <main>'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `each'
/usr/local/bundle/gems/activerecord-6.0.2.1/lib/active_record/railties/databases.rake:84:in `block (2
 levels) in <main>'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:23:in `block in perfo
rm'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/command.rb:48:in `invoke'
/usr/local/bundle/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
require'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `
block in require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `re
gister'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `
require_with_bootsnap_lfi'
/usr/local/bundle/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `
require'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in requ
ire'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependen
cy'
/usr/local/bundle/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
/app/bin/rails:9:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/rails.rb:28:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client/command.rb:7:in `call'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/client.rb:30:in `run'
/usr/local/bundle/gems/spring-2.1.0/bin/spring:49:in `<top (required)>'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `load'
/usr/local/bundle/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
/app/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

$ docker-compose exec db mysql -e "SHOW TABLE STATUS FROM db1 WHERE Name = 'posts'\\G" \
| grep Row_format:                                                                 
     Row_format: Compact
mysql:5.5  # success (warning), compact
mysql:5.6  # error (since rails sets STRICT_ALL_TABLES), compact
mysql:5.7  # success, dynamic
mysql:8    # success, dynamic
mariadb:5.5   # success (warning), compact
mariadb:10.0  # error (since rails sets STRICT_ALL_TABLES), compact
mariadb:10.1  # error (since rails sets STRICT_ALL_TABLES), compact
mariadb:10.2  # success, dynamic
mariadb:10.3  # success, dynamic
mariadb:10.4  # success, dynamic

rails sets STRICT_ALL_TABLES.

To try with another db image:

$ docker-compose stop db
$ docker-compose rm -f db
$ docker volume prune -f
$ docker-compose pull
$ docker-compose up -d
$ docker-compose exec -T app sh -c 'wait4ports tcp://db:3306 && cd app && RAILS_LOG_TO_STDOUT=1 bin/rails db:migrate'

Another way to reproduce the issue:

1.sql:

SET SESSION sql_mode = 'STRICT_ALL_TABLES';
DROP TABLE posts;
CREATE TABLE posts (
    id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    title VARCHAR(255)
) CHARACTER SET = 'utf8mb4';
ALTER TABLE posts ADD INDEX (title(255));
SHOW CREATE TABLE posts;
$ cat 1.sql | docker-compose exec db mysql --show-warnings --auto-vertical-output -vt db1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment