jazzband / django-two-factor-auth

Complete Two-Factor Authentication for Django providing the easiest integration into most Django projects.
MIT License
1.71k stars 448 forks source link

the backend doesn't support altering from/to AutoField. #528

Closed atila7840 closed 2 years ago

atila7840 commented 2 years ago

I am using MS SQL as DB and two factor, when I run migrate I get error : Running migrations: File "C:\Python310\lib\site-packages\mssql\schema.py", line 287, in _alter_field raise NotImplementedError("the backend doesn't support altering from/to %s." % t.name) NotImplementedError: the backend doesn't support altering from/to AutoField.

Also when run python -Wa manage.py test

I get error: Found 0 test(s). C:\Python310\lib\site-packages\two_factor\views\utils.py:11: RemovedInDjango50Warning: The django.utils.baseconv module is deprecated. from django.utils import baseconv System check identified no issues (0 silenced).

python manage.py runserver Watching for file changes with StatReloader Performing system checks...

System check identified no issues (0 silenced).

You have 1 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): two_factor. Run 'python manage.py migrate' to apply them.

Your Environment

pip list Package Version


asgiref 3.5.0 atpublic 3.0.1 attrs 22.1.0 colorama 0.4.5 dj-database-url 0.5.0 Django 4.0.5 django-formtools 2.3 django-otp 1.1.3 django-phonenumber-field 6.3.0 django-recaptcha 3.0.0 django-two-factor-auth 1.14.0 jedi 0.18.1 mssql-django 1.1.3 parso 0.8.3 phonenumbers 8.12.53 pip 22.2.2 pycryptodome 3.15.0 pyodbc 4.0.34 pytz 2022.1 pytz-deprecation-shim 0.1.0.post0 qrcode 7.3.1 setuptools 58.1.0 six 1.16.0 sqlparse 0.4.2 tzdata 2022.1 tzlocal 4.2

claudep commented 2 years ago

I'm a bit afraid we can't do much here, but still, can you identify the migration which causes this error?

atila7840 commented 2 years ago

D:\MyDjangoProjects\partnik>python manage.py migrate Operations to perform: Apply all migrations: PollApp1, admin, auth, contenttypes, otp_email, otp_static, otp_totp, sessions, two_factor Running migrations: Applying two_factor.0008_alter_phonedevice_id...Traceback (most recent call last): File "D:\MyDjangoProjects\partnik\manage.py", line 22, in main() File "D:\MyDjangoProjects\partnik\manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Python310\lib\site-packages\django\core\management__init__.py", line 446, in execute_from_command_line utility.execute() File "C:\Python310\lib\site-packages\django\core\management__init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python310\lib\site-packages\django\core\management\base.py", line 414, in run_from_argv self.execute(*args, cmd_options) File "C:\Python310\lib\site-packages\django\core\management\base.py", line 460, in execute output = self.handle(*args, *options) File "C:\Python310\lib\site-packages\django\core\management\base.py", line 98, in wrapped res = handle_func(args, kwargs) File "C:\Python310\lib\site-packages\django\core\management\commands\migrate.py", line 290, in handle post_migrate_state = executor.migrate( File "C:\Python310\lib\site-packages\django\db\migrations\executor.py", line 131, in migrate state = self._migrate_all_forwards( File "C:\Python310\lib\site-packages\django\db\migrations\executor.py", line 163, in _migrate_all_forwards state = self.apply_migration( File "C:\Python310\lib\site-packages\django\db\migrations\executor.py", line 248, in apply_migration state = migration.apply(state, schema_editor) File "C:\Python310\lib\site-packages\django\db\migrations\migration.py", line 131, in apply operation.database_forwards( File "C:\Python310\lib\site-packages\django\db\migrations\operations\fields.py", line 235, in database_forwards schema_editor.alter_field(from_model, from_field, to_field) File "C:\Python310\lib\site-packages\django\db\backends\base\schema.py", line 747, in alter_field self._alter_field( File "C:\Python310\lib\site-packages\mssql\schema.py", line 287, in _alter_field raise NotImplementedError("the backend doesn't support altering from/to %s." % t.name__) NotImplementedError: the backend doesn't support altering from/to AutoField.

claudep commented 2 years ago

The migration two_factor.0008_alter_phonedevice_id doesn't belong to this package. My guess it that the migration was automatically created in your project due to a different DEFAULT_AUTO_FIELD setting. I'll let you investigate this idea.

atila7840 commented 2 years ago

I checked the table id field, it's primary key and identity. also I commented DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' but I got: D:\MyDjangoProjects\partnik>python manage.py migrateSystem check identified some issues: WARNINGS:two_factor.PhoneDevice: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'.        HINT: Configure the DEFAULT_AUTO_FIELD setting or the TwoFactorConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'.Operations to perform:  Apply all migrations: PollApp1, admin, auth, contenttypes, otp_email, otp_static, otp_totp, sessions, two_factorRunning migrations:  Applying two_factor.0008_alter_phonedevice_id...Traceback (most recent call last):  File "D:\MyDjangoProjects\partnik\manage.py", line 22, in     main()

On Tuesday, August 23, 2022 at 12:36:41 AM GMT+4:30, Claude Paroz ***@***.***> wrote:  

The migration two_factor.0008_alter_phonedevice_id doesn't belong to this package. My guess it that the migration was automatically created in your project due to a different DEFAULT_AUTO_FIELD setting. I'll let you investigate this idea.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

claudep commented 2 years ago

I guess the solution in your case might be to create a custom app config, something like this:

from two_factor.plugins.phonenumber.apps import TwoFactorPhoneNumberConfig

class CustomPhoneAppConfig(TwoFactorPhoneNumberConfig):
    default_auto_field = 'django.db.models.AutoField'

Then in your INSTALLED_APPS setting, point to that config, so instead of: two_factor.plugins.phonenumber use: path.to.CustomPhoneAppConfig

atila7840 commented 2 years ago
How can I deactivate phone number capability as I am going to use email Instead.I think this can be a suitable workaround for me.  Sent from Mail for Windows From: Claude ParozSent: Tuesday, August 23, 2022 10:57 AMTo: jazzband/django-two-factor-authCc: atila; AuthorSubject: Re: [jazzband/django-two-factor-auth] the backend doesn't support altering from/to AutoField. (Issue #528) I guess the solution in your case might be to create a custom app config, something like this:from two_factor.plugins.phonenumber.apps import TwoFactorPhoneNumberConfig class CustomPhoneAppConfig(TwoFactorPhoneNumberConfig):    default_auto_field = 'django.db.models.AutoField'Then in your INSTALLED_APPS setting, point to that config, so instead of:two_factor.plugins.phonenumberuse:path.to.CustomPhoneAppConfig—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.IMessage ID: ***@***.***> 
claudep commented 2 years ago

Please comment directly on the GitHub interface, as your mail client is sending completely broken content.