При попытке изменить пароль в админке появляется ошибка ограничение внешнего ключа.
models.py и views.py
forum.models
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=255, unique=True)
first_name = models.CharField(max_length=30, null=True, blank=True)
last_name = models.CharField(max_length=30, null=True, blank=True)
email = models.EmailField(max_length=255, unique=True)
password1 = models.CharField(max_length=255)
password2 = models.CharField(max_length=255)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(u'date joined', default=timezone.now)
objects = UserManager()
avatar = models.ImageField(settings.AUTH_USER_MODEL, default='media/no_image.jpg', blank=True)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email', 'password', 'avatar']
profile_user.models
class Profile(models.Model):
# user = models.OneToOneField(User, on_delete=models.CASCADE)
# user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, verbose_name='User')
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='profile_user', verbose_name='User')
avatar = models.ImageField(settings.AUTH_USER_MODEL, default='media/no_image.jpg', blank=True)
views.py
def signup(request):
if request.method == 'POST':
form = SignupForm(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.is_active = False
user.save()
# save form in the memory not in database
# to get the domain of the current site
current_site = get_current_site(request)
mail_subject = 'Activation link has been sent to your email id'
message = render_to_string('acc_active_email.html', {
'form': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
to_email = form.cleaned_data.get('email')
email = EmailMessage(
mail_subject, message, to=[to_email]
)
email.send()
return HttpResponse('Пожалуйста перейди по ссылке и заверши регистрацию')
else:
form = SignupForm()
return render(request, 'signup.html', {'form': form})
Traceback Switch to copy-and-paste view
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 89, in _execute
return self.cursor.execute(sql, params) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py, line 477, in execute
return Database.Cursor.execute(self, query, params) …
Local vars
The above exception (FOREIGN KEY constraint failed) was the direct cause of the following exception:
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/core/handlers/exception.py, line 55, in inner
response = get_response(request) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/core/handlers/base.py, line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/utils/decorators.py, line 133, in _wrapped_view
response = view_func(request, *args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/views/decorators/cache.py, line 62, in _wrapped_view_func
response = view_func(request, *args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/contrib/admin/sites.py, line 242, in inner
return view(request, *args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/utils/decorators.py, line 46, in _wrapper
return bound_method(*args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/views/decorators/debug.py, line 92, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/contrib/auth/admin.py, line 167, in user_change_password
self.log_change(request, user, change_message) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/contrib/admin/options.py, line 934, in log_change
return LogEntry.objects.log_action( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/contrib/admin/models.py, line 38, in log_action
return self.model.objects.create( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/manager.py, line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/query.py, line 514, in create
obj.save(force_insert=True, using=self.db) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/base.py, line 806, in save
self.save_base( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/base.py, line 857, in save_base
updated = self._save_table( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/base.py, line 1000, in _save_table
results = self._do_insert( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/base.py, line 1041, in _do_insert
return manager._insert( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/manager.py, line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/query.py, line 1434, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/models/sql/compiler.py, line 1621, in execute_sql
cursor.execute(sql, params) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 103, in execute
return super().execute(sql, params) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 67, in execute
return self._execute_with_wrappers( …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 80, in _execute_with_wrappers
return executor(sql, params, many, context) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 89, in _execute
return self.cursor.execute(sql, params) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/utils.py, line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/utils.py, line 89, in _execute
return self.cursor.execute(sql, params) …
Local vars
/home/ioann/.local/share/virtualenvs/new_project-VB4uMZT5/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py, line 477, in execute
return Database.Cursor.execute(self, query, params) …
Local vars