I’m trying to move my n8n version 1.51.2 setup to Google Cloud SQL and Cloud Run. The data migration from my old PostgreSQL database to the new cloud instance went smoothly, and I can confirm all the tables are there.
When I deploy the Docker container with n8n 1.51.2, it connects to the cloud database fine, but then I run into this issue during startup:
Error: There was an error running database migrations
QueryFailedError: relation "migrations" already exists
This is confusing because the migrations table is clearly already present in the database. Why would n8n try to create it again? Can someone explain how the migration process works and what triggers it?
I thought it would just start up normally without trying to run migrations since the database schema is already in place.
n8n uses TypeORM to track completed migrations in that table. When you moved your data, those migration records probably got corrupted or went missing - even though your table structure looks fine. I’ve hit this same issue migrating between PostgreSQL versions. The schema was there, but TypeORM couldn’t tell which migrations had already run. Before you drop tables, try clearing n8n’s cache and temp files first, then restart the container. Also check if your cloud database has different collation settings than your original setup - TypeORM sometimes misreads existing schemas because of this. Honestly though, the safest bet is exporting your workflows and credentials separately, then doing a clean n8n install on the new database.
Had the same issue last month when switching cloud providers. n8n finds your database but gets confused by the migration tracking system. Check what’s actually inside your migrations table, not just whether it exists. The table might be there but have broken or incomplete entries that mess with TypeORM’s migration runner. Query the migrations table directly - see if all the expected entries are there and formatted correctly. If they look wrong or incomplete, you’ll need to clean them up manually or let n8n rebuild the table from scratch. Also make sure your Google Cloud SQL instance runs the exact same PostgreSQL version as your original database. Even small version differences can break migration detection.
yea, it might be a version thing, or maybe n8n’s just confused. try dropping the migrations table - i had that same issue when switching setups and rebuilding worked wonders for me.