After click on Submit button Value error is occur.
I got this error:
Field 'id' expected a number but got 'Shailesh'.
Request Method: POST
Request URL: http://127.0.0.1:8000/contact/
Django Version: 3.0.5
Exception Type: ValueError
Exception Value:
Field 'id' expected a number but got 'shailesh'.
Exception Location: C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\db\models\fields_init_.py in get_prep_value, line 1774
Python Executable: C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\python.exe
Python Version: 3.8.2
Python Path:
['C:\Users\Shailesh\Desktop\Django_In_One_Video\Hello',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\python38.zip',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\DLLs',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32',
'C:\Users\Shailesh\AppData\Roaming\Python\Python38\site-packages',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib\site-packages',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\win32\lib',
'C:\Users\Shailesh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\Pythonwin']
Server time: Fri, 3 Apr 2020 16:23:17 +0000
I delete all migrations and migrate again the same problem is occurring.
Top comments (8)
Looks like you are assigning some string to id which should be a autofield.
Show the view where you create and save the object then I can assist you further.
Hello Soumya,
Following is my views.py:
from django.shortcuts import render
from home.models import Contact
Create your views here.
def index(request):
def about(request):
return render(request,'about.html')
def services(request):
return render(request,'services.html')
def contact(request):
if request.method =="POST":
name=request.POST.get('name')
phone=request.POST.get('phone')
email=request.POST.get('email')
desc=request.POST.get('desc')
obj1=Contact(name,phone,email,desc)
obj1.save()
def str(self):
self.name
Where you create obj1 there instead of creating objects using positional arguments use keyword arguments.
So change line will look like
The keywords should be the name of the columns in the model
Hello Soumya,
After changing it's working fine. Thanks for my correction. Please reply me back with your contact details. I want to add you to my contact.
You can contact me on telegram on
t.me/soumya_r
Hello Pavel,
I tried this method and now it is working fine. Thanks for my correction. I will use code blocks in my post. Thanks again. Please reply to me with your contact details. I want to add you to my contact.
Hello Pavel,
Following is my views.py:
from django.shortcuts import render
from home.models import Contact
Create your views here.
def index(request):
def about(request):
return render(request,'about.html')
def services(request):
return render(request,'services.html')
def contact(request):
if request.method =="POST":
name=request.POST.get('name')
phone=request.POST.get('phone')
email=request.POST.get('email')
desc=request.POST.get('desc')
obj1=Contact(name,phone,email,desc)
obj1.save()
def str(self):
self.name
Okay. No Issue. Again Thanks for Correction