我正在尝试将我的用户模型更改为自定义模型。我不介意删除我的数据库并只使用一个新数据库,但是当我尝试运行 makemigrations 时,我收到此错误
bookings.Session.session_client: (fields.E301) Field defines a relation with the model 'auth.User', which has been swapped out.
HINT: Update the relation to point at 'settings.AUTH_USER_MODEL'.
Run Code Online (Sandbox Code Playgroud)
预订/views.py
from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse, HttpResponseRedirect
from bookings.models import Session
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
# Create your views here.
def book(request, Session_id):
lesson = get_object_or_404(Session, pk=Session_id)
try:
client = request.user.id
except (KeyError, Choice.DoesNotExist):
return render(request, 'booking/details.html', {
'lesson': lesson,
'error_message': "You need to login first", …Run Code Online (Sandbox Code Playgroud)