Render
Table of contents
- Can’t connect to MySQL server on ‘…’ ([Errno 111] Connection refused)
- ERROR [flask_migrate] Error: Can’t locate revision identified by
Can’t connect to MySQL server on ‘…’ ([Errno 111] Connection refused)
The deploy log shows wait-for-db.sh succeeding (MariaDB is up - executing command) and, a moment later,
flask db upgrade failing with:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '<hostname>' ([Errno 111] Connection refused)")
wait-for-db.sh and the entrypoint connect with -P $MARIADB_PORT, so the database is reachable and the port is
right. The application builds its own connection string, and older copies of the repository took it straight from
splent_framework, which hardcodes port 3306 whatever MARIADB_PORT says: the application could never reach a
database on another port even with the variable set correctly. Check that your app/__init__.py contains
_apply_database_port; if it does not, bring it up to date with the course repository and redeploy.
A wrong MARIADB_PORT looks different: the log never reaches flask db upgrade and loops on
MariaDB is unavailable - sleeping. Copy the port from the Filess.io panel; it is not 3306 by default.
ERROR [flask_migrate] Error: Can’t locate revision identified by
This is due to a cache problem or a problem with the migration checking system.
Delete migration in Filess.io database
A common error is often migrations. If you encounter the error ERROR [flask_migrate] Error: Can't locate revision identified by... it means that there has been a conflict with the Flask cache. It is very easy to solve it:
- We go to the management panel of our Filess.io database.
- Click on
Web Client. - Click on the table
alembic_version. - Identify the conflicting migration on the right, right click,
Delete rows (s). - To apply the changes, click on
Savein the bottom menu. - This should now allow the normal deployment process. Render makes several attempts, but if it doesn’t, click
Manual DeployandClear build cache & deploy.
Check that migrations are in a consistent state
If, after several continuous deployments, you still encounter the problem of migrations, perform these steps in your development environment:
-
Check current migration state: Use the Flask-Migrate command to show the current state of migrations. Run the following command in your terminal:
flask db currentThis will show you the current migration version applied to your database.
-
Compare migration deads: Ensure that the migration head in your database matches the head of your migration scripts. Run the following command to show the head of your migrations:
flask db headsIf the heads do not match, there might be pending migrations that need to be applied.
-
Apply pending migrations: If there are pending migrations, apply them by running:
flask db upgradeThis command will apply any new migrations to bring your database schema up to date.
-
Verify migration history: To see the history of migrations applied, you can use the following command:
flask db historyThis will display the list of all migrations applied in chronological order.
-
Check for inconsistencies: If you suspect inconsistencies, you can verify the integrity of your migrations by comparing the actual database schema with your migration scripts. Use the
flask db stampcommand to stamp the database with the correct version if necessary:flask db stamp headThis command ensures that the migration version in your database matches the latest migration script.