service references one service_generation (as the latest_generation_id) and service_generation references service.id, which poses an issue when trying to insert. To get around this, I am trying to use deferrable fk constraints + transactions.DEFERRABLE INITIALLY DEFERRED to the FOREIGN KEY line in the migration.commit; is ran. PRAGMA defer_foreign_keys = true; should also completely disable fk checks until the end of the transaction.