CleanCut / green

Green is a clean, colorful, fast python test runner.
MIT License
785 stars 75 forks source link

django.db.utils.ProgrammingError: relation "users_user" does not exist #251

Closed vanities closed 2 years ago

vanities commented 2 years ago

Hello! Thank you for your test runner, I love it :)

I'm trying to run my django tests with the following requirements:

green==3.3.0
Django==3.2.9

With python 3.9

And I'm getting the following error:

Error in ..
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.UndefinedTable: relation "users_user" does not exist
LINE 1: UPDATE "users_user" SET "password" = 'some-password', "last_...
               ^

The above exception was the direct cause of the following exception:

  File "/usr/local/lib/python3.9/site-packages/green/suite.py", line 147, in _handleClassSetUpPost38
    setUpClass()
  File "/usr/local/lib/python3.9/site-packages/django/test/testcases.py", line 1194, in setUpClass
    call_command('loaddata', *cls.fixtures, **{'verbosity': 0, 'database': db_name})
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 181, in call_command
    return command.execute(*args, **defaults)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
    self.loaddata(fixture_labels)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
    self.load_label(fixture_label)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/loaddata.py", line 190, in load_label
    obj.save(using=self.using)
  File "/usr/local/lib/python3.9/site-packages/django/core/serializers/base.py", line 223, in save
    models.Model.save_base(self.object, using=using, raw=True, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 763, in save_base
    updated = self._save_table(
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 845, in _save_table
    updated = self._do_update(base_qs, using, pk_val, values, update_fields,
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 899, in _do_update
    return filtered._update(values) > 0
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 802, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
    cursor = super().execute_sql(result_type)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: Problem installing fixture '/myproj/users/fixtures/users.yaml': Could not load users.User(pk=1): relation "users_user" does not exist
LINE 1: UPDATE "users_user" SET "password" = 'some-password', "last_...

Is there something I'm doing wrong?

Thanks!

CleanCut commented 2 years ago

Hello! Thank you for your test runner, I love it :)

Aww, thanks! ❤️

Is there something I'm doing wrong?

I really can't tell from the error alone. You should know that I've never used Django myself other than to get Green working with it (which involved following Django's documentation and a trivial "hello world" django app), so I may not be much help. However, perhaps if we look a little deeper we can figure it out.

vanities commented 2 years ago

Thanks for responding so quickly!

You won't believe this, but I ran it this morning and it failed with this issue, but when I just ran it, it didn't. I'll close if for now. Thanks! Lol

Edit: I think it has something to do with a test involving our migrations: with this app, https://github.com/wemake-services/django-test-migrations

CleanCut commented 2 years ago

I'm glad you were able to resolve the issue!