I am getting an error when I try to access the admin panel. It says ValidationError at /admin/["'urvi' value must be an integer."].
I have already tried using id and auto incrementing it but nothing works.
Models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
Roles = (
('sales', 'SALES'),
('operations', 'OPERATIONS'),
('cashier', 'CASHIER'),
('frontdesk', 'FRONTDESK'),
('admin', 'ADMIN'),
('client', 'CLIENT'),
)
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, default='none')
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField(max_length=100, unique=True)
password = models.CharField(max_length=50)
username = models.CharField(max_length=50)
role = models.CharField(max_length=50, choices=Roles, default='client')
def __str__(self):
return self.username
urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from NewApp import views
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^$',views.register,name='register'),
user
is a OneToOneField
and the default you provide is a string! How can the ORM know how to translate that string to a User
instance? You can either provide an int
there which is questionable because you have make sure a User
with that id is present in the database. Or - which is maybe what you want - make the field nullable ( null=True
) and set the default to None
(not 'none'
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.