migration error
Added by Edward Beb about 14 hours ago
Hi All!
I have problem with migration in docker. When I start docker containers I have an error:
rails aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'redmine_development.settings' doesn't exist (ActiveRecord::StatementInvalid)
Here is my docker compose file:
services:
db:
image: mysql:latest
volumes:
- ./tmp/cache/mysql:/var/lib/mysql
- ./tmp/conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
environment:
MYSQL_DATABASE: redmine_development
MYSQL_ROOT_PASSWORD: 'password'
ports:
- "3307:3306"
web:
build:
context: .
dockerfile: Dockerfile.dev
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
environment:
DATABASE_URL: mysql2://root:password@db:3306/redmine_development?pool=5
ports:
- "3001:3000"
depends_on:
- db
volumes:
- ".:/app"
Replies (2)
RE: migration error
-
Added by Edward Beb about 13 hours ago
Environment:
Redmine version 5.1.9.stable
Ruby version 3.2.8-p263 (2025-03-26) [x86_64-linux]
Rails version 6.1.7.10
Environment development
Database adapter Mysql2
Mailer queue ActiveJob::QueueAdapters::AsyncAdapter
Mailer delivery smtp
Redmine settings:
Redmine theme Default
SCM:
Git 2.34.1
Filesystem
RE: migration error
-
Added by Lionel BAKALA about 11 hours ago
Hi Edward,
The solution to this inconvenience is called wait-for-it.
tree -a . ├── config │ └── database.yml ├── docker-compose.yml ├── Dockerfile.redmine ├── .env ├── plugins └── wait-for-it.sh
Download it with:
curl -o wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
Dockerfile.redmine:
FROM redmine:5.1.9 RUN apt-get update && apt-get install -y \ imagemagick \ libmagickwand-dev \ && rm -rf /var/lib/apt/lists/* WORKDIR /usr/src/redmine COPY wait-for-it.sh ./wait-for-it.sh RUN chmod +x ./wait-for-it.sh
docker-compose.yml:
services: mariadb: image: mariadb:10.6 restart: always environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} volumes: - mariadb_data:/var/lib/mysql redmine: build: context: . dockerfile: Dockerfile.redmine depends_on: - mariadb entrypoint: > bash -c " ./wait-for-it.sh mariadb:3306 --timeout=30 --strict && bundle exec rake db:migrate && bundle exec rails server -b 0.0.0.0" ports: - "3001:3000" environment: REDMINE_DB_MYSQL: ${REDMINE_DB_MYSQL} REDMINE_DB_DATABASE: ${REDMINE_DB_DATABASE} REDMINE_DB_USERNAME: ${REDMINE_DB_USERNAME} REDMINE_DB_PASSWORD: ${REDMINE_DB_PASSWORD} volumes: - redmine_files:/usr/src/redmine/files - ./config/database.yml:/usr/src/redmine/config/database.yml - ./plugins:/usr/src/redmine/plugins volumes: mariadb_data: redmine_files:
The Redmine container must wait for the database to be ready before running the migration. Hence:
entrypoint: > bash -c " ./wait-for-it.sh mariadb:3306 --timeout=30 --strict && bundle exec rake db:migrate && bundle exec rails server -b 0.0.0.0"
.env:
MYSQL_ROOT_PASSWORD=rootpass MYSQL_DATABASE=redmine MYSQL_USER=redmine MYSQL_PASSWORD=redminepass REDMINE_DB_MYSQL=mariadb REDMINE_DB_DATABASE=redmine REDMINE_DB_USERNAME=redmine REDMINE_DB_PASSWORD=redminepass
config/database.yml:
production: adapter: mysql2 database: <%= ENV['REDMINE_DB_DATABASE'] %> host: <%= ENV['REDMINE_DB_MYSQL'] %> username: <%= ENV['REDMINE_DB_USERNAME'] %> password: <%= ENV['REDMINE_DB_PASSWORD'] %> encoding: utf8mb4