I have a fairly large django app that I usually test using pytest --no-migrations (as the migrations take ages), but since I added a ManyToMany relationship this way:
class Object(models.Model):
# ...
collections = models.ManyToManyField(Collection, through=Collection.products.through, blank=True)
class Collection(models.Model):
# ...
products = models.ManyToManyField("objects.Object", blank=True)
Of course, I generated and executed the migrations.
Running pytest works fine, but running pytest --nomigrations throws this error on every test:
self = <django.db.backends.utils.CursorWrapper object at 0xffff91150820>
sql = 'CREATE TABLE "brand_collections_collection_products" ("id" bigserial NOT NULL PRIMARY KEY, "collection_id" bigint NOT NULL, "object_id" bigint NOT NULL)', params = None
ignored_wrapper_args = (False, {'connection': <django.db.backends.postgresql.base.DatabaseWrapper object at 0xffff94ed1330>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0xffff91150820>})
def _execute(self, sql, params, *ignored_wrapper_args):
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors:
if params is None:
# params default might be backend specific.
> return self.cursor.execute(sql)
E django.db.utils.ProgrammingError: relation "brand_collections_collection_products" already exists
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:82: ProgrammingError
I have no idea what this error means in this context, or why it suddenly triggers, and I could not find an easy answer online...