1

I have a 2.2 Django project with django-otp==0.8.0, django-two-factor-auth[phonenumbers]==1.14.0, and an app two_factor_auth that makes use of these two libraries.

When tests are run with migrations, they pass:

$ ./manage.py test two_factor_auth
  Applying two_factor.0001_initial... OK
  Applying two_factor.0002_auto_20150110_0810... OK
  Applying two_factor.0003_auto_20150817_1733... OK
  Applying two_factor.0004_auto_20160205_1827... OK
  Applying two_factor.0005_auto_20160224_0450... OK
  Applying two_factor.0006_phonedevice_key_default... OK
  Applying two_factor.0007_auto_20201201_1019... OK
----------------------------------------------------------------------
Ran 13 tests in 5.549s

OK

Note that these migrations are the ones from the django-two-factor-auth package as the two-factor-auth app has no migrations.

However, when tests are run without migrations (as is done in CI and local environments because our project has hundreds of migrations), they fail:

$ ./manage.py test two_factor_auth --nomigrations

Traceback (most recent call last):
  File "/opt/miniconda3/lib/python3.8/site-packages/two_factor/views/profile.py", line 38, in get_context_data
    'default_device': default_device(self.request.user),
  File "/opt/miniconda3/lib/python3.8/site-packages/two_factor/utils.py", line 16, in default_device
    for device in devices_for_user(user):
  File "/opt/miniconda3/lib/python3.8/site-packages/django_otp/__init__.py", line 80, in devices_for_user
    for device in model.objects.devices_for_user(user, confirmed=confirmed):
  File "/opt/miniconda3/lib/python3.8/site-packages/django/db/models/query.py", line 274, in __iter__
    self._fetch_all()
  ...
  File "/opt/miniconda3/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: two_factor_phonedevice

I can confirm that this issue no longer appears if I go back to using django-otp==0.7.5 and django-two-factor-auth==1.9.1.

What could be the problem?

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Konrad
  • 11
  • 1
  • 1
    Hi @Konrad, I have thhe same problem. Were you able to find a solution? – Salvatore Iovene Jan 29 '23 at 15:24
  • Hi @Salvatorelovene, I did indeed. I listed one in https://github.com/jazzband/django-two-factor-auth/issues/519 and the pull request that resolved the actual issue is also linked. – Konrad Jan 31 '23 at 00:52

1 Answers1

0

I got the same error below with django-two-factor-auth==1.15.3:

django.db.utils.OperationalError: no such table: two_factor_phonedevice

So, I restarted the server, then the error was solved but one day I got the error again. I don't know how to solve the error completely and why the error occurs:

python manage.py runserver 0.0.0.0:8000
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129