表“auth_user”中不存在键(user_id)=(7)

时间:2018-03-09 13:01:05

标签: django django-rest-framework django-authentication

我正在使用djoser的创建令牌结束点来登录用户,但我收到以下错误。 enter image description here

我试过谷歌搜索但找不到任何有用的答案。

更新 我已经定制了用户模型,以便在注册用户时添加额外的字段。 这是我的models.py

from django.db import models
from custom_user.models import AbstractEmailUser


class UserProfile(AbstractEmailUser):
    account_address = models.CharField(max_length=100, blank=True)
    name = models.CharField(max_length=30, blank=True)

这是我的serializer.py

from djoser.serializers import UserCreateSerializer as BaseUserRegistrationSerializer
from rest_framework import serializers


class UserRegistrationSerializer(BaseUserRegistrationSerializer):
    advertisements = serializers.HyperlinkedRelatedField(many=True, view_name='advertisement-detail', read_only=True)

    class Meta(BaseUserRegistrationSerializer.Meta):
        fields = ('id', 'email', 'advertisements', 'name', 'account_address', 'password')

和urls.py

from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter


router = DefaultRouter()

urlpatterns = [
    url(r'^account/', include('djoser.urls')),
    url(r'^account/', include('djoser.urls.authtoken'))
]

0 个答案:

没有答案