django.db.utils.IntegrityError: duplicate key value violates unique constraint "users_customuser_email_6445acef_uniq"
DETAIL: Key (email)=() already exists.
User should be created.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin, AdminUserCreationForm
from .models import CustomUser
class CustomUserCreationForm(AdminUserCreationForm):
class Meta(AdminUserCreationForm.Meta):
model = CustomUser
fields = ("username", "email")
@admin.register(CustomUser)
class CustomUserAdmin(UserAdmin):
model = CustomUser
add_form = CustomUserCreationForm
# Include email in the add view fieldsets
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": ("username", "email", "usable_password", "password1", "password2"),
},
),
)
Bug Description
Problem Description
When attempting to add a new user through the Django Admin interface at /admin/users/customuser/add/, an IntegrityError is thrown:
Steps to Reproduce
Expected Behavior
User should be created.
Screenshots / Logs
No response
Platform
Proxmox
Install Method
Quick Install Script
AdventureLog Version
v0.13.0
Reverse Proxy
none
Docker Compose / Relevant Variables (Optional)
Additional Context
Proposed fix:
Define a CustomUserCreationForm derived from django.contrib.auth.forms.AdminUserCreationForm that explicitly includes the email field, and assign it to CustomUserAdmin.add_form and CustomUserAdmin.add_fieldsets.
Confirmation