-1

So I'm getting this error in django 1.8. and django-registration-redux 1.1 . It doesn't let me sleep from 3 weeks. Help would be good .

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

This is my 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 file

    """
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'

If there is anything else required for to question the answer please let me know , i m new to framework and django . So i don't really know much about it .

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • The error tells you that you are trying to save a model instance without setting the `activated` flag. However, you haven't given enough information to explain why. Please update your question with the full traceback, and the rest of registration config. – Alasdair Apr 06 '16 at 14:59
  • @Alasdair hi , I just updated the question , if there is anything else you need just let me know , i m in my learning curve rightnow so don't really know what is required for what. Thanks again and if there is anything i should take care in future regarding django and python just let me know. – Maitrey Prajapati Apr 07 '16 at 14:45
  • There's not enough information there. You haven't included the full traceback, and I can't see how you have configured registration. – Alasdair Apr 07 '16 at 14:47
  • @Alasdair i just updated the question with full traceback, and i don't really know what you are trying to say "How did you configured registration" , I installed it via pip and then put it inside the Installed apps. I am using this functionality for first time . – Maitrey Prajapati Apr 08 '16 at 01:25
  • There is a copy paste view of the traceback that is easier to read. You must have done other stuff to configure registration, e.g. adding it to your urls. – Alasdair Apr 08 '16 at 07:32

3 Answers3

1

I had the same problem as you. I tried to change the url like:

url(r'^accounts/', include('registration.backends.simple.urls')),

hope this helps.

mar_mj
  • 11
  • 1
0

I think you have installed the wrong version of Django registration.

The traceback contains

/registration/backends/model_activation/views.py in register

However the model_activation backend does not exist in django-registration-redux (see the directory on GitHub). I think you have django-registration (not redux) 2.x installed instead.

If you are following a tutorial, it's important to make sure you have the packages and versions installed, otherwise you'll hit problems like this.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
0

Completely delete your Database. In your case, delete the db.sqlite3 in the same folder as your manage.py. Keep the .py files inside the <your app>/migrations folder, donot delete them.

And then run python manage.py migrate

And then setup all the data again in the database.

Sushovan Mandal
  • 1,027
  • 3
  • 13
  • 32