迁移失败,因为auth.User



我正在尝试使用rest_framework.authtoken我按照这个说明https://www.django-rest-framework.org/api-guide/authentication/#tokenauthentication

但是当我尝试执行python manage。py migrate

authtoken.Token.user: (fields.E300) Field defines a relation with model 'auth.User', which is either not installed, or is abstract.
authtoken.Token.user: (fields.E307) The field authtoken.Token.user was declared with a lazy reference to 'auth.user', but app 'auth' isn't installed.

这个错误发生

我看到错误信息,认为我需要安装"auth">

所以Ipip install django-rest-auth但它没有工作

这是我的settings。py

INSTALLED_APPS = [
'rest_auth',
'rest_framework.authtoken',
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}

它是views.py(我正在工作,所以它还没有完成)

@api_view(http_method_names=['POST'])
@permission_classes([AllowAny])
@psa()
def exchange_token(request, backend):
serializer = UserSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
user = request.backend.do_auth(serializer.validated_data['access_token'])
if user:#drf built in token authentication??
token, _ = Token.objects.get_or_create(user=user) # drf token authentication
return Response({'token':token.key})
else:
return Response(
{'errors':{'token':'Invalid token'}},
status = status.HTTP_400_BAD_REQUEST,
)

我正在尝试使用" token。objects~~"没有我可以修复的迁移文件。文档告诉我要做python manage.py migrate

谁能告诉我出了什么事?

请先运行

`python manage.py makemigrations`

最新更新