Database migration issue when moving n8n to cloud SQL

Hey everyone,

I’m having trouble with my n8n setup. I moved my 1.51.2 installation to a cloud SQL database and GCP cloud run. I got the data moved over fine, and the Docker container is up. It’s connecting to the new database, but I’m getting some weird errors on startup.

The main error says it can’t run database migrations. It’s trying to create a ‘migrations’ table, but that already exists. Here’s what I’m seeing:

Error: There was an error running database migrations
QueryFailedError: relation "migrations" already exists

I’m confused about why it’s trying to do this. When does n8n usually try to run migrations? I thought it would just start up normally without trying to mess with the database structure.

Has anyone run into this before? Any ideas on how to fix it? I’m kind of stuck here and would really appreciate some help. Thanks!

hey there, i’ve had this happen too. it’s a pain! have u tried clearing the migrations table? sometimes that fixes it. just run ‘TRUNCATE TABLE migrations;’ in ur SQL console. then restart n8n. might solve ur problem without messin with the whole db. good luck!

I’ve encountered a similar issue when migrating n8n to cloud environments. In my experience, this often happens when the database schema is out of sync with what n8n expects.

One thing that worked for me was to temporarily disable migrations on startup. You can do this by setting the N8N_DISABLE_PRODUCTION_MAIN_PROCESS environment variable to true. This lets n8n start up without trying to run migrations.

Once it’s running, you might need to manually run the migrations using the n8n command line tool. Something like ‘n8n start --tunnel’ usually does the trick.

After that, you can remove the environment variable and restart n8n. It should then recognize the migrations as complete and start up normally.

Hope this helps! Let me know if you need any clarification on the steps.

I’ve dealt with this migration hiccup before when moving n8n to cloud environments. It’s a tricky situation, but there’s a workaround.

Try clearing the ‘migrations’ table in your cloud SQL database before starting n8n. This allows n8n to recreate the migration history from scratch, which often resolves the conflict.

To do this, connect to your cloud SQL instance and run:

DROP TABLE IF EXISTS migrations;

After that, restart your n8n container. It should then be able to create the migrations table and proceed with any necessary schema updates.

If you’re still encountering issues, double-check that your database user has the necessary permissions to create and modify tables. Sometimes cloud SQL setups can have unexpected permission restrictions.

Let us know if this resolves your problem or if you need further assistance.