所以我在django 1.8中遇到了这个错误。和django-registration-redux 1.1 。它不会让我从3周后睡觉。帮助会很好。
IntegrityError at /accounts/register/
NOT NULL constraint failed: registration_registrationprofile.activated
Request Method: POST
Request URL: http://localhost:8000/accounts/register/
Django Version: 1.8
Exception Type: IntegrityError
Exception Value:
NOT NULL constraint failed: registration_registrationprofile.activated
Exception Location: /Users/Maitrey/bookstore-django/lib/python2.7/site- packages/django/db/backends/sqlite3/base.py in execute, line 318
Python Executable: /Users/Maitrey/bookstore-django/bin/python
Python Version: 2.7.10
Python Path:
['/Users/Maitrey/Udemy_Django/Developement/bookstore',
'/Users/Maitrey/bookstore-django/lib/python27.zip',
'/Users/Maitrey/bookstore-django/lib/python2.7',
'/Users/Maitrey/bookstore-django/lib/python2.7/plat-darwin',
'/Users/Maitrey/bookstore-django/lib/python2.7/plat-mac',
'/Users/Maitrey/bookstore-django/lib/python2.7/plat-mac/lib- scriptpackages',
'/Users/Maitrey/bookstore-django/Extras/lib/python',
'/Users/Maitrey/bookstore-django/lib/python2.7/lib-tk',
'/Users/Maitrey/bookstore-django/lib/python2.7/lib-old',
'/Users/Maitrey/bookstore-django/lib/python2.7/lib-dynload',
' /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/Maitrey/bookstore-django/lib/python2.7/site-packages']
Server time: Wed, 6 Apr 2016 11:49:25 +0000
FULL Traceback
Traceback Switch to copy-and-paste view
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/core/handlers/base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/views/generic/base.py in view
return self.dispatch(request, *args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/registration/views.py in dispatch
return super(RegistrationView, self).dispatch(*args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/views/generic/base.py in dispatch
return handler(request, *args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/views/generic/edit.py in post
return self.form_valid(form) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/registration/views.py in form_valid
new_user = self.register(form) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/registration/backends/model_activation/views.py in register
site=get_current_site(self.request) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/utils/decorators.py in inner
return func(*args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/registration/models.py in create_inactive_user
registration_profile = self.create_profile(new_user) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/registration/models.py in create_profile
activation_key=activation_key) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/manager.py in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/query.py in create
obj.save(force_insert=True, using=self.db) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/base.py in save
force_update=force_update, update_fields=update_fields) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/base.py in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/base.py in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/base.py in _do_insert
using=using, raw=raw) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/manager.py in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/query.py in _insert
return query.get_compiler(using=using).execute_sql(return_id) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql
cursor.execute(sql, params) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return super(CursorDebugWrapper, self).execute(sql, params) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return self.cursor.execute(sql, params) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/utils.py in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/backends/utils.py in execute
return self.cursor.execute(sql, params) ...
▶ Local vars
/Users/Maitrey/bookstore-django/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute
return Database.Cursor.execute(self, query, params) ...
▶ Local vars
这是我的registration_form.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post" action = ".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Register" />
</form>
</body>
</html>
settings.py文件
"""
Django settings for bookstore project.
Generated by 'django-admin startproject' using Django 1.9.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<secret key>'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#'django.contrib.sites',
'store',
'registration',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'bookstore.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'bookstore.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
#Registration
ACCOUNT_ACTIVATIONS_DAYS = 7
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/store/'
#Email Settings
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
Email_HOST = "smtp.gmail.com"
EMAIL_HOST_USER ="mwork@gmail.com"
EMAIL_HOST_PASSWORD = "<password>"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'mwork@gmail.com'
如果还有其他问题需要回答,请告诉我,我是框架和django的新手。所以我真的不太了解它。
答案 0 :(得分:1)
我和你有同样的问题。我试着改变网址:
url(r'^accounts/', include('registration.backends.simple.urls')),
希望这会有所帮助。
答案 1 :(得分:0)
我认为您安装了错误版本的Django注册。
回溯包含
/registration/backends/model_activation/views.py in register
然而,django-registration-redux中不存在model_activation
后端(请参阅GitHub上的the directory)。我认为你安装了django-registration(而不是redux)2.x。
如果您正在阅读教程,确保安装了软件包和版本非常重要,否则您将遇到类似的问题。
答案 2 :(得分:0)
完全删除您的数据库。在您的情况下,请删除与db.sqlite3
位于同一文件夹中的manage.py
。将.py
文件保留在<your app>/migrations
文件夹中,不要删除它们。
然后运行python manage.py migrate
然后在数据库中再次设置所有数据。