Tuesday, 20 August 2013

IntegrityError: null value in column "email" violates not-null constraint

IntegrityError: null value in column "email" violates not-null constraint

I just start to learn Django. While I'm trying to create a very simple
user register function(with PSQL),but I always got this message:
Integrity error: null value in column "email" violates not-null constraint
I think there is something wrong with my database. But I couldn't figure
it why..
THANK YOU VERY MUCH!!
I'm using Django 1.5.1 and PSQL 9.1.9
models.py:
from django.db import models
class User(models.Model):
name = models.CharField(max_length=30)
email = models.EmailField(verbose_name='e-mail',blank=True)
password = models.CharField(max_length=16)
views.py:
from portfolioSite.forms import register_form
from django.shortcuts import render
from django.http import HttpResponseRedirect
from portfolioSite.models import User
def register(request):
if request.method == 'POST':
registerForm = register_form(request.POST)
if registerForm.is_valid():
User.objects.create(name = registerForm.cleaned_data['name'],
email = registerForm.cleaned_data['email'],
password = registerForm.cleaned_data['password2'])
return HttpResponseRedirect('/success/')
else:
registerForm = register_form()
return render(request, 'register_form.html', {'form':registerForm})
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
in get_response
115. response = callback(request,
*callback_args, **callback_kwargs)
File "/home/guangyi/Django/projects/mysite/portfolioSite/views.py" in
register
13. password =
registerForm.cleaned_data['password2']
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py"
in create
149. return self.get_query_set().create(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in
create
402. obj.save(force_insert=True, using=self.db)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in
save
546. force_update=force_update,
update_fields=update_fields)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py" in
save_base
650. result = manager._insert([self], fields=fields,
return_id=update_pk, using=using, raw=raw)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py"
in _insert
215. return insert_query(self.model, objs, fields, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in
insert_query
1661. return query.get_compiler(using=using).execute_sql(return_id)
File
"/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py"
in execute_sql
937. cursor.execute(sql, params)
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py"
in execute
41. return self.cursor.execute(sql, params)
File
"/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py"
in execute
56. six.reraise(utils.IntegrityError,
utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2])
File
"/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql_psycopg2/base.py"
in execute
54. return self.cursor.execute(query, args)
Exception Type: IntegrityError at /register/
Exception Value: null value in column "email" violates not-null constraint

No comments:

Post a Comment