1

Currently I started a project to learn more of django + jwt and react.

Instead of using sql I used mongodb with django instead by using djongo.

It works pretty well setting things up, creating new model to test out. So I started looking for django + jwt tutorials and come upon this tutorial

https://hackernoon.com/110percent-complete-jwt-authentication-with-django-and-react-2020-iejq34ta

Everything works fine up until the end about blacklisting tokens

I have my settings.py as suggested

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=14),
    'ROTATE_REFRESH_TOKENS': True,
    'BLACKLIST_AFTER_ROTATION': True,
    'ALGORITHM': 'HS256',
    'SIGNING_KEY': SECRET_KEY,
    'VERIFYING_KEY': None,
    'AUTH_HEADER_TYPES': ('JWT',),
    'USER_ID_FIELD': 'id',
    'USER_ID_CLAIM': 'user_id',
    'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
    'TOKEN_TYPE_CLAIM': 'token_type',
}

by making the BLACKLIST_AFTER_ROTATION to True, I need to do a migration by python manage.py migrate

This is where the error happens, error I got is

djongo.sql2mongo.SQLDecodeError: FAILED SQL: CREATE TABLE "token_blacklist_blacklistedtoken" ("id" int32 NOT NULL PRIMARY KEY AUTOINCREMENT, "blacklisted_at" date NOT NULL)

I was poking around and couldn't get a solution so I tried changing db back using mysql instead, then the migration worked like a charm.

Does anyone know if I do keep using mongodb instead of mysql, is there a workaround for this migration and functionality to work?

Thanks in advance for any advices.

Dora
  • 6,776
  • 14
  • 51
  • 99
  • Got a similar error ..if you figured this out, you might have an idea of what I should do. Please check [this](https://stackoverflow.com/q/73002707/12601926) out. – sajeyks mwangi Jul 16 '22 at 08:35

1 Answers1

0

Just a suggestion just change USER_ID_FIELD to email or user_name and try to run the migration. It looks like Mongo is trying to create two-column with the name 'id'.

You can use SQL and no-SQL depending on the requirement. If your app needs both then use advanced Postgres in the project. JSONField has better solutions.