On deployment I get: [error] Could not create schema migrations table.

In multiple attempts to deploy a fresh phoenix app, I get the following error:

[error] Could not create schema migrations table. This error usually happens due to the following:
	   * The database does not exist
	   * The "schema_migrations" table, which Ecto uses for managing
	     migrations, was defined by another library
	   * There is a deadlock while migrating (such as using concurrent
	 ** (Postgrex.Error) ERROR 42501 (insufficient_privilege) permission denied for schema public
	     (ecto_sql 3.9.2) lib/ecto/adapters/sql.ex:913: Ecto.Adapters.SQL.raise_sql_call_error/1
	     (elixir 1.14.3) lib/enum.ex:1658: Enum."-map/2-lists^map/1-0-"/2
	 Starting clean up.

Before attempting to deploy, I ran mix ecto.create without running ecto migration yet.
I’ve also deleted the previous fly launch artifacts and started allover again without success. Please, any way to fix this problem?

Hi @Uzo,

If you compare with a newly generated Phoenix 1.6 application and deploy that, your fly.toml file should include this line:

  release_command = "/app/bin/migrate"

This assumes the migrate script is present in the Dockerfile. The Dockerfile is created during fly launch

What this does is run migrations before starting your app. If this early step is failing, then check that the db username and password used by the application has permission to create tables. By default it should. This would only be the case if you are restricting access.

Hi @Mark , thanks for the swift response.

I don’t think I am restricting access in any way. Perhaps I should comment out the release_command = "/app/bin/migrate" part since I am not ready for migration just yet. Please, would that be the right approach?
Just want to have a “Site Under Construction” page on my Fly.io site for now.

Hi @Uzo,

Is this a brand new app and it’s creating the DB for the first time? That’s what it sounds like. Or is this an existing app with existing data?

Yes @Mark, It’s a brand new app without existing data.

A fix was just released in a new flyctl version.

Run flyctl version update.

This addressed an issue for newly created DBs from just this morning.

The easiest fix is to delete the newly created app and postgres app and re-create it with the updated flyctl.

Sorry for the issue!

Thank you Mark, I’ll try it out.

1 Like