NOT NULL constraint failed: home_contact.name
Я продолжаю получать эту ошибку, даже если все имена атрибутов одинаковы в Contact.html и view.py untegrityError at /contact Сбой ограничения NOT NULL: home_contact.name Также выполнил миграцию и миграцию, все равно нет решения
views.py from django.shortcuts import render,HttpResponse from datetime import datetime from home.models import Contact # Создайте свои представления здесь. def index(request): # return HttpResponse("This Is Homepage") # To Render String Use HttpResponse контекст = { 'variable' : "This IS SEND 121212", 'v2' : "V@" } return render(request,'index.html',context) # Render Menas It Load The index.html file and send the data of context def about(request): # return HttpResponse("This Is About") # To Render String Use HttpResponse return render(request,'about.html') # Render Menas It Load The index.html file and send the data of context
def services(request):
# return HttpResponse("This Is Services") # To Render String Use HttpResponse
return render(request,'services.html') # Render Menas It Load The index.html file and send the data of context
def contact(request):
# return HttpResponse("This Is Contact") # To Render String Use HttpResponse
if request.method == "POST":
name = request.POST.get('nme')
print(name)
# email = request.POST.get('email')
# print(email)
# pwd = request.POST.get('pwd')
# print(pwd)
c1 = Contact(name=name)
# contact = Contact(name=name,email=email,pwd=pwd,date=datetime.today())
c1.save()
return render(request,'contact.html') # Render Menas It Load The index.html file and send the data of context
contact.html
{% extends 'base.html' %}
{% block title %}Contact{% endblock title %}
{% block body %}
<div class="container-fluid px-0 mb-3">
<img src="static\img\IM-1.jpg" width="1200" height="400" class="d-block w-100 mx-0" alt="...">
</div>
<div class="container mb-3 py-4">
<h3 class="text-center">Contact Us</h3>
<form method = "post" action = "/contact">
{% csrf_token %}
{% comment %} Without This It Get Error {% endcomment %}
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="nme" name"nme" aria-describedby="emailHelp" placeholder="Enter Name" >
{% comment %} </div>
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" aria-describedby="emailHelp" name"email" placeholder"Enter Email" name"email">
<div id="emailHelp" class="form-text">We'll never share your email with anyone else.</div>
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Password</label>
<input type="password" class="form-control" id="pwd" name"pwd">
</div> {% endcomment %}
<button type="submit" class="btn btn-primary mb-3">Submit</button>
</form>
</div>
{% endblock body %}
models.py
from django.db import models
# Create your models here.
class Contact(models.Model):
name = models.CharField(max_length=122)
# email = models.CharField(max_length=122)
# pwd = models.CharField(max_length=122)
# date = models.DateField()
Полная ошибка:...
IntegrityError at /contact
Сбой ограничения NOT NULL: home_contact.name
Метод запроса: POST
URL запроса: http://127.0.0.1:8000/contact.
Версия Django: 4.0.3
Тип исключения: IntegrityError
Значение исключения:
Сбой ограничения NOT NULL: home_contact.name
Exception Location: C:\Users\jaysi\AppData\Local\Programs\Python\Python310\lib\site-packages\django\db\backends\sqlite3\base.py, line 477, in execute
Python Executable: C:\Users\jaysi\AppData\Local\Programs\Python\Python310\python.exe
Версия Python: 3.10.2
Python Path:
['E:\Codes\ML_I\Django\Hello',
'C:\Users\jaysi\AppData\Local\Programs\Python\Python310\python310.zip',
'C:\Users\jaysi\AppData\Local\Programs\Python\Python310\DLLs',
'C:\Users\jaysi\AppData\Local\Programs\Python\Python310\lib',
'C:\Users\jaysi\AppData\Local\Programs\Python\Python310',
'C:\Users\jaysi\AppData\Local\Programs\Python\Python310\lib\site-packages'].
Время сервера: Sat, 12 Mar 2022 12:23:58 +0000