Table 'openmrs.person_attribute_type' doesn't exist

Application Name: Reference Application

Version Number: 2.12

Question:

I am trying to run the OpenMRS Reference Application from docker-compose. When it starts up, I see the following error sequence in the log:

  • There was an error while updating the database to the latest. file: org/openmrs/liquibase/updates/liquibase-update-to-latest-2.0.x.xml. Error: Migration failed for change set liquibase-update-to-latest.xml::1::upul:
  • Failed SQL: (1146) ALTER TABLE openmrs.person_attribute_type ADD edit_privilege VARCHAR(255) NULL
  • reason: Table ‘openmrs.person_attribute_type’ doesn’t exist

Here are my .env file entries for docker-compose:

OPENMRS_VERSION=2.12
COMPOSE_PROJECT_NAME=openmrs
DB_CREATE_TABLES=true
DB_AUTO_UPDATE=true
MODULE_WEB_ADMIN=true

I also tried it with all combinations of DB_CREATE_TABLES and DB_AUTO_UPDATE true vs false.

Attached is my docker-compose file.

Here is the contents of my docker-compose.yml:

version: '3'

services:
  openmrs-referenceapplication-mysql:
    restart: "always"
    image: mysql:5.6
    command: "mysqld --character-set-server=utf8 --collation-server=utf8_general_ci"
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: ${MYSQL_DB:-openmrs}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-Admin123}
      MYSQL_USER: ${MYSQL_USER:-openmrs}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-Admin123}
    healthcheck:
      test: "exit 0"
    volumes:
      - ./openmrs_mysql_dbdump:/docker-entrypoint-initdb.d
      - openmrs-referenceapplication-mysql-data:/var/lib/mysql  # uncomment to keep database between docker runs

  openmrs-referenceapplication:
    restart: "always"
    image: openmrs/openmrs-reference-application-distro:${OPENMRS_VERSION:-qa}
    logging:
      options:
        max-size: "10m"
        max-file: "3"
    depends_on:
      - openmrs-referenceapplication-mysql
    ports:
      - "8080:8080"
    environment:
      DB_DATABASE: ${MYSQL_DB:-openmrs}
      DB_HOST: openmrs-referenceapplication-mysql
      DB_USERNAME: ${MYSQL_USER:-openmrs}
      DB_PASSWORD: ${MYSQL_PASSWORD:-Admin123}
      DB_CREATE_TABLES: 'false'
      DB_AUTO_UPDATE: 'false'
      MODULE_WEB_ADMIN: 'false'
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/openmrs/"]
      timeout: 20s

volumes:
  openmrs-referenceapplication-mysql-data:

OK, so it seems that my error stems from the fact that Liquibase is trying to apply change-sets, but there is no existing schema/snapshot in the database (db only contains the two Liquibase tables: openmrs.liquibasechangelog and openmrs.liquibasechangeloglock).

So, I assume this means I have to manually create the initial schema? How do I do this, and why is this not part of the initial setup of the Reference Application?

Set DB_CREATE_TABLES to true to have the database tables created.

Ah, I made a booboo. I had DB_CREATE_TABLES=true in my .env file, but in the docker-compose.yml I had earlier hard-coded DB_CREATE_TABLES=false, so it was using that, not the true value from the .env file.