0

I'm trying to migrate a production database to google cloud sql using the replication method described here. However, when importing the mysql dump file google cloud sql returns the error ''Cannot Add Foreign Key Constraint''.

I've checked if there are any foreign key vialotions using this method. However, there are no violations in the database.

Therefore, I've tracked down the problem to be due to circular references. The only option seems to be to disable FOREIGN_KEY_CHECKS during the import. However, I cannot find any method to set this flag.

Are there any recommendations on how to continue from here?

  • Possible duplicate of [How to temporarily disable a foreign key constraint in MySQL?](https://stackoverflow.com/questions/15501673/how-to-temporarily-disable-a-foreign-key-constraint-in-mysql) – Nae Jun 12 '19 at 15:52
  • 1
    No it isn't. It targets the google cloud sql solution and specifically the described migration method that allows a transition with minimal downtime using the replication method. – Kevin Müller Jun 12 '19 at 21:34
  • 1
    In that case perhaps [drop FK's in the dump](https://stackoverflow.com/a/50010817/7032856) as a workaround. – Nae Jun 13 '19 at 07:09

1 Answers1

1
SET FOREIGN_KEY_CHECKS := NOT @@FOREIGN_KEY_CHECKS
;

Will toggle FK control in mysql.

Nae
  • 14,209
  • 7
  • 52
  • 79
  • My question is regarding google cloud sql. When migrating from an external server I see no possibility to perform such a query before the replication is successfull. – Kevin Müller Jun 12 '19 at 18:55