Closed jessamynsmith closed 1 year ago
Same problem here after upgrading from 1.14.0 to 1.15.0. Downgraded back to 1.14.0 for now until this migration is added.
I notice a similar migration named 0008_delete_phonedevice.py. My guess is that the model is to be phased out.
It is not phased out, it has been moved to plugins/phonenumber/models.py
, but Django does not seem to look for the migration in plugins/phonenumber/migrations
and thinks it needs to create a new one.
Adding two_factor.plugins.phonenumber
to INSTALLED_APPS
kind of fixes the problem (but then you’ll have phone number authentication enabled).
Should be fixed by 2ff98b514d42db97d7c9fdabe2face86fc6f8188
I'm still getting a ghost migration in CI on a project with django-two-factor-auth (on a dependabot PR to upgrade to 1.15.1):
./manage.py makemigrations --dry-run --no-input --check
Migrations for 'two_factor':
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/two_factor/migrations/0002_phonedevice.py
- Create model PhoneDevice
Not sure what makes this "phonedevice" model appear?
Ah yes, it looks like #596 is still needed to avoid that (as currently phonenumber plugin views are imported in base urls.py, which is incidentally registering the Phone model in the apps registry).
From experience this is an issue because the new Django default for DEFAULT_AUTO_FIELD
in the settings file is "django.db.models.BigAutoField"
whereas the phonenumber app has not defined a default. So there is a mismatch and an extra migration file needs to be generated.
If you change your settings DEFAULT_AUTO_FIELD
to "django.db.models.AutoField"
then the migrations work fine. If we run migrations with this change enabled https://github.com/jazzband/django-two-factor-auth/commit/008dd920f39812e8e59563fd657cd0a4edfe5f2a then it works fine.
So we probably need another release to make sure this is fixed for all new users.
Can confirm, with django-two-factor-auth master, when I run makemigrations
in my project, no extra migrations are being generated.
Thanks for testing that!
Thanks for testing that!
Sure thing! But I think it introduced another issue: https://github.com/jazzband/django-two-factor-auth/issues/627.
Expected Behavior
I would expect that when creating a new project, installing django-two-factor-auth, and running migrate, that no further migrations would need to be made for the two factor app.
Current Behavior
When installing django-two-factor-auth and running makemigrations, it is generating a migration for the two_factor app:
Possible Solution
If the issue is that a migration is missing, generate and commit it. If the problem is that a model is in the wrong app, perhaps remove it from that app. Note: this issue was introduced in version 1.15.0; if I install 1.14.0 there are no migration issues.
Steps to Reproduce (for bugs)
python manage.py makemigrations
Context
This issue can be avoided by only ever generating migrations for my own apps, but that is a bit tedious.
Your Environment