citusdata / django-multitenant

Python/Django support for distributed multi-tenant databases like Postgres+Citus
MIT License
721 stars 119 forks source link

Dropping foreign keys fails with "cannot execute multiple utility events" #34

Closed louiseGrandjonc closed 4 years ago

louiseGrandjonc commented 5 years ago

Here is what happens.

When dropping a model, the default migration drops foreign key constraints. And is executed in a single transaction:

SET CONSTRAINTS "my_fk_constraint" IMMEDIATE; ALTER TABLE "my_table" DROP CONSTRAINT "my_fk_constraint"

On the shards are executed

SELECT worker_apply_shard_ddl_command (102259, 'public', 'SET CONSTRAINTS "my_fk_constraint" IMMEDIATE; ALTER TABLE "my_table" DROP CONSTRAINT "my_fk_constraint"')

This fails with the error cannot execute multiple utility events

In the django it comes from
https://github.com/django/django/blob/master/django/db/backends/postgresql/schema.py#L21

In the backend, it would be great to avoid that.

The goal is for customer to be able to use auto-generated migrations to drop models.

louiseGrandjonc commented 5 years ago

Test with citus 8.3

louiseGrandjonc commented 4 years ago

Fixed since https://github.com/citusdata/django-multitenant/pull/50/files