Migrate up error: Dirty database version

I am trying to setup the chirpstack application server. I have followed all the steps which are provided in the quick start guide. My network server is up and running but my application-server fails with the below error.

Stopped ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Started ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.350096999Z" level=info msg="starting ChirpStack Application Server" docs="https://www.chirpstack.io/" version=3.17.2
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.353836457Z" level=info msg="storage: setting up storage package"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354033983Z" level=info msg="storage: setup metrics"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354196187Z" level=info msg="storage: setting up Redis client"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.354364219Z" level=info msg="storage: connecting to PostgreSQL database"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.360196351Z" level=info msg="storage: applying PostgreSQL data migrations"
Oct 18 03:20:28 ip-172-31-25-97 chirpstack-application-server[25451]: time="2021-10-18T03:20:28.363729949Z" level=fatal msg="setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version."
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Main process exited, code=exited, status=1/FAILURE
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Failed with result 'exit-code'.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Service hold-off time over, scheduling restart.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Scheduled restart job, restart counter is at 5.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Stopped ChirpStack Application Server.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Start request repeated too quickly.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: chirpstack-application-server.service: Failed with result 'exit-code'.
Oct 18 03:20:28 ip-172-31-25-97 systemd[1]: Failed to start ChirpStack Application Server.

I re-installed Postgres but that too didn’t work.

I am using postgres 10.18 and ubuntu 18

Are you using the same database for the ChirpStack Network Server and ChirpStack Application Server? In that case I recommend to create two new empty databases and retry.

No, I am using different empty databases but still, the error is coming. I then upgraded my OS to ubuntu 20 and after that I was able to run chirpstack application server and visit the interface.

I’ve tried the installation several times on Ubuntu 20.04 Focal Fossa . I ended up with the same error as follow.
level=fatal msg=“setup storage error: storage: migrate up error: Dirty database version 27. Fix and force version.”

It indicates that somehow, it could migrate the database. The Dirty database version indicates that a previous run failed. Please inspect the logs to see what went wrong at that migration run.