Google Social Authentication troubles - google-chrome

Hi I am new to social login's. When I click the google button I can get redirected to a working social view. As I attempt to log in I get the following trackback.
I have been having a very difficult time understanding how this all works can someone please give me a hand? I tried multiple tutorials on google social authentication.
Traceback (most recent call last):
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\views.py", line 33, in complete
*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\actions.py", line 43, in do_complete
user = backend.complete(user=user, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 40, in complete
return self.auth_complete(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\utils.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\oauth.py", line 405, in auth_complete
*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\utils.py", line 259, in wrapper
return func(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\oauth.py", line 416, in do_auth
return self.strategy.authenticate(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\strategy.py", line 107, in authenticate
return authenticate(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\django\contrib\auth\__init__.py", line 73, in authenticate
user = backend.authenticate(request, **credentials)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 80, in authenticate
return self.pipeline(pipeline, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 83, in pipeline
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\backends\base.py", line 113, in run_pipeline
result = func(*args, **out) or {}
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\pipeline\user.py", line 75, in create_user
'user': strategy.create_user(**fields)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_core\strategy.py", line 53, in create_user
return self.storage.user.create_user(*args, **kwargs)
File "C:\Users\bmxfi\Anaconda3\envs\QuestionWorldEnv\lib\site-packages\social_django\storage.py", line 79, in create_user
user = cls.user_model().objects.create_user(*args, **kwargs)
TypeError: create_user() missing 3 required positional arguments: 'first_name', 'last_name', and 'date_of_birth'
[22/Jan/2019 00:30:51] "GET /auth/complete/google-oauth2/?state=9RDDB6MAo3C5i0MDKQuHBX9QOiyEQBcB&code=4/2gDFXySOhdxEVkI4gMXQ9vNUhpuEvqm1rYoCxgM85d6LrNu2HqhnjRNcUs9ZzRql4KMbdWVpXO0NACsS111yhSY&scope=email+profile+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email HTTP/1.1" 500 184864
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'World1',
'social_django',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
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',
'social_django.middleware.SocialAuthExceptionMiddleware', # <--
]
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.debug.debug',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'social.pipeline.debug.debug',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]
# Google+ SignIn (google-plus)
SOCIAL_AUTH_GOOGLE_PLUS_IGNORE_DEFAULT_SCOPE = True
SOCIAL_AUTH_GOOGLE_PLUS_SCOPE = [
'https://www.googleapis.com/auth/plus.login',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile'
]

All that was needed here was the setting
SOCIAL_AUTH_GOOGLE_LOGIN_URL='/auth/complete/google-oauth2/'
I had this setting as LOGIN_URL instead of SOCIAL_AUTH_GOOGLE_LOGIN_URL.
and then change my LOGIN_URL to the template after the user gets authenticated not the actual login template itself.

Related

OperationalError: no such table: django_content_type and django_session

I cannot access my app, when I enter the URL, it gives me the error
OperationalError: no such table: django_session
This usually means I need to migrate, or delete my sqlite database and redo migrations, so I did that multiple times. I deleted everything in the migrations folder and sqlite3.db and ran:
python manage.py makemigrations app_name
python manage.py migrate app_name
No errors yet. Then after creating a superuser I run:
python manage.py runserver
It tells me 18 migrations have not been made, which I was able to fix with:
python manage.py migrate --fake
I try the site and again I get the no such table: django_session error.
I read this thread
Django: no such table: django_session
and tried everything in it, including the approved solution, same error.
Also, when I try to run the migrate command again, I get this error
OperationalError: no such table: django_content_type
so I went to this thread
sqlite3.OperationalError: no such table: django_content_type
once again, the solutions that worked for them did not work for me.
This problem started after we migrated to MySQL, I tried to switch databases using a .env file, but ran into these problems, so I tried to switch back to sqlite so I can at least work on the project. The team is in the middle of moving to MySQL, and we have people working successfully with both databases, so it shouldn't be a database issue.
Here is my settings.py file:
import os
from pathlib import Path
from django.contrib.messages import constants as message_constants
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
SECRET_KEY = os.environ.get("DJ_SECRET_KEY", default="Testing")
DEBUG = os.environ.get("DJ_DEBUG", default=True)
ALLOWED_HOSTS = ["redonkulator.apps.dev.mach9.usmc.mil", "localhost", "127.0.0.1"]
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"redonkulator_app.apps.RedonkulatorAppConfig",
"jquery",
"debug_toolbar",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.middleware.common.CommonMiddleware",
"debug_toolbar.middleware.DebugToolbarMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]
ROOT_URLCONF = "iiimef_project.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["templates"],
"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",
],
},
},
]
AUTH_USER_MODEL = "redonkulator_app.MlptUsers"
WSGI_APPLICATION = "iiimef_project.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": os.environ.get("SQL_ENGINE", "django.db.backends.sqlite3"),
"NAME": os.environ.get(
"SQL_DATABASE",
os.path.join(BASE_DIR, "db.sqlite3"),
),
"USER": os.environ.get("SQL_USER", "user"),
"PASSWORD": os.environ.get("SQL_PASSWORD", "password"),
"HOST": os.environ.get("SQL_HOST", "localhost"),
"PORT": os.environ.get("SQL_PORT", "5432"),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/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/3.2/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/3.2/howto/static-files/
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
LOGIN_REDIRECT_URL = ""
LOGOUT_REDIRECT_URL = "/about"
LOGIN_URL = "/login"
MESSAGE_STORAGE = "django.contrib.messages.storage.cookie.CookieStorage"
# needed to overwrite bootsrap classes
MESSAGE_TAGS = {
message_constants.DEBUG: "debug",
message_constants.INFO: "info",
message_constants.SUCCESS: "success",
message_constants.WARNING: "warning",
message_constants.ERROR: "danger",
}
INTERNAL_IPS = [
"127.0.0.1",
]
I have session and contenttype in my installed apps and sessions in my middleware, is there anything in here that looks obviously wrong?
Here is my .env
DJ_SECRET_KEY=super-secret-key
DJ_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] 0.0.0.0 *
DJ_DEBUG=True
SQL_DATABASE=redonkulator
SQL_ENGINE=django.db.backends.mysql
SQL_USER=[myusername]
SQL_PASSWORD=[mypassword]
SQL_HOST=localhost
SQL_PORT=3306
I know that this .env won't work with my settings, and that's okay as I'm just trying to get sqlite to work for now.
One more thing, starting today, slightly after this problem started, every django import is underlined in yellow. For example "django.contrib.messages" in settings.py is underlined, however I don't get a module import error, so I don't think that's the issue.
Finally, here is the traceback for the content_type error:
Traceback (most recent call last):
File "C:\Users\dwill\Documents\GitHub\MLPT\manage.py", line 22, in <module>
main()
File "C:\Users\dwill\Documents\GitHub\MLPT\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\commands\migrate.py", line 268, in handle
emit_post_migrate_signal(
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\management\sql.py", line 42, in emit_post_migrate_signal
models.signals.post_migrate.send(
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\dispatch\dispatcher.py", line 180, in send
return [
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\dispatch\dispatcher.py", line 181, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\auth\management\__init__.py", line 42, in create_permissions
create_contenttypes(app_config, verbosity=verbosity, interactive=interactive, using=using, apps=apps, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\contenttypes\management\__init__.py", line 119, in create_contenttypes
content_types, app_models = get_contenttypes_and_models(app_config, using, ContentType)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\contenttypes\management\__init__.py", line 94, in get_contenttypes_and_models
content_types = {
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\query.py", line 280, in __iter__
self._fetch_all()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\query.py", line 1324, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\query.py", line 51, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\sql\compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: django_content_type
and the django session error:
Traceback (most recent call last):
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
The above exception (no such table: django_session) was the direct cause of the following exception:
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\admin\sites.py", line 414, in login
return LoginView.as_view(**defaults)(request)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\auth\views.py", line 63, in dispatch
return super().dispatch(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\views\generic\edit.py", line 142, in post
return self.form_valid(form)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\auth\views.py", line 92, in form_valid
auth_login(self.request, form.get_user())
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\auth\__init__.py", line 111, in login
request.session.cycle_key()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\sessions\backends\base.py", line 344, in cycle_key
self.create()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\sessions\backends\db.py", line 51, in create
self._session_key = self._get_new_session_key()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\sessions\backends\base.py", line 196, in _get_new_session_key
if not self.exists(session_key):
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\contrib\sessions\backends\db.py", line 47, in exists
return self.model.objects.filter(session_key=session_key).exists()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\query.py", line 808, in exists
return self.query.has_results(using=self.db)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\sql\query.py", line 550, in has_results
return compiler.has_results()
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\sql\compiler.py", line 1145, in has_results
return bool(self.execute_sql(SINGLE))
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\models\sql\compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\debug_toolbar\panels\sql\tracking.py", line 198, in execute
return self._record(self.cursor.execute, sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\debug_toolbar\panels\sql\tracking.py", line 133, in _record
return method(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\dwill\Documents\GitHub\MLPT\myenv\lib\site-packages\django\db\backends\sqlite3\base.py", line 423, in execute
return Database.Cursor.execute(self, query, params)
Exception Type: OperationalError at /admin/login/
Exception Value: no such table: django_session
Try avoiding the .env file to rule that out.
Update settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DBNAME',
'USER': 'USER',
'PASSWORD': 'PASS',
'HOST': '127.0.0.1',
'PORT': 3306
}
}
If this works then we have found the source of the problem and should double-check the location of the .env file and work backwards from there.
After making your migrations, try sync your database:
python manage.py migrate --run-syncdb
It has solved this error code for me several times.

Django: Getting Interface Error, Exception Value: (0, '') when using remote MySQL DB but not local DB

Trying to login to my app, I am getting this error when I am using a MySQL DB hosted remotely but not when I am connecting to my locally hosted XAMPP one.
I've read a couple entries on my question but they mostly mention cursors that aren't explicitly closed, which I don't need to since I am using with in all my raw queries.
I am using django-allauth for my authentication.
Traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/accounts/login/?next=/
Django Version: 3.1.2
Python Version: 3.8.6
Installed Applications:
['ewhale_app',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'users.apps.UsersConfig',
'pages.apps.PagesConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
return self.cursor.execute(query, args)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
res = self._query(query)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
db.query(q)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\connections.py", line 259, in query
_mysql.connection.query(self, query)
The above exception ((0, '')) was the direct cause of the following exception:
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\allauth\account\views.py", line 138, in dispatch
return super(LoginView, self).dispatch(request, *args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\allauth\account\views.py", line 78, in dispatch
response = super(RedirectAuthenticatedUserMixin,
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\allauth\account\views.py", line 94, in get
response = super(AjaxCapableProcessFormViewMixin, self).get(
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\views\generic\edit.py", line 133, in get
return self.render_to_response(self.get_context_data())
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\allauth\account\views.py", line 169, in get_context_data
site = get_current_site(self.request)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\sites\shortcuts.py", line 13, in get_current_site
return Site.objects.get_current(request)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\sites\models.py", line 58, in get_current
return self._get_site_by_id(site_id)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\contrib\sites\models.py", line 30, in _get_site_by_id
site = self.get(pk=site_id)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 425, in get
num = len(clone)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 269, in __len__
self._fetch_all()
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 1308, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\models\sql\compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
return self.cursor.execute(query, args)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\cursors.py", line 206, in execute
res = self._query(query)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\cursors.py", line 319, in _query
db.query(q)
File "C:\Users\Ej\AppData\Local\Programs\Python\Python38\lib\site-packages\MySQLdb\connections.py", line 259, in query
_mysql.connection.query(self, query)
Exception Type: InterfaceError at /accounts/login/
Exception Value: (0, '')
Would appreciate feedback on where to check the issue.
Avoided this issue by recreating a new DB and migrating.

Trouble connecting MySQL to Heroku using Django

I have recently switched my Django database from SQLite to MySQL. I have Heroku's free MySQL database installed, called ClearDB and am using this documentation: https://devcenter.heroku.com/articles/cleardb. I can create/install the app and get the url for the database using the following commands:
heroku addons:create cleardb:ignite
heroku config | findstr CLEARDB_DATABASE_URL
heroku config | set DATABASE_URL= # MySQL database url retrieved from above line
After I do this, push everything to Heroku with my database change(which works locally) and open the app, I get the following traceback:
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template error:
In template /app/profiles/templates/base.html, error at line 0
2002
1 :
2 : <!DOCTYPE html>
3 : {% load staticfiles %}
4 :
5 : {% block styles %}
6 : {% endblock %}
7 :
8 :
9 : <style type="text/css">
10 :
Traceback:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
194. self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in get_new_connection
236. return Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/__init__.py" in Connect
86. return Connection(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in __init__
204. super(Connection, self).__init__(*args, **kwargs2)
The above exception ((2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")) was the direct cause of the following exception:
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/profiles/views.py" in home
17. return render(request, template, context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/shortcuts.py" in render
36. content = loader.render_to_string(template_name, context, request, using=using)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader.py" in render_to_string
62. return template.render(context, request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
175. return self._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
167. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
155. return compiled_parent._render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in _render
167. return self.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/loader_tags.py" in render
67. result = block.nodelist.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render
943. bit = node.render_annotated(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
211. nodelist.append(node.render_annotated(context))
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/base.py" in render_annotated
910. return self.render(context)
File "/app/.heroku/python/lib/python3.6/site-packages/django/template/defaulttags.py" in render
168. len_values = len(values)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __len__
254. self._fetch_all()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
1179. self._result_cache = list(self._iterable_class(self))
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
54. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
1061. cursor = self.connection.cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in cursor
255. return self._cursor()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in _cursor
232. self.ensure_connection()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py" in __exit__
89. raise dj_exc_value.with_traceback(traceback) from exc_value
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection
216. self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect
194. self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/mysql/base.py" in get_new_connection
236. return Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/__init__.py" in Connect
86. return Connection(*args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/MySQLdb/connections.py" in __init__
204. super(Connection, self).__init__(*args, **kwargs2)
Exception Type: OperationalError at /
Exception Value: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
I am still learning, and not sure how to troubleshoot this traceback. If you could help me understand what I'm doing wrong, that would be great.

Django /admin trying to use SQLlite DB when MySQL is installed

Newbie. Have googled, and seeing nothing.
Trying to get into admin/ and it says:
/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py in get_new_connection, line 346
[It is trying to use SQLlite as database].
But I have MySQL as the database--and the other functions in regards to using MySQL work correctly. (it updates MySQL database when adding new apps).
I even manually checked MySQL database, and it has the superuser that I added!
Anyone have any ideas?
Environment:
full stack trace:
Request Method: POST Request URL: ommitted/
Django Version: 1.6.2 Python Version: 2.6.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback: File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py" in wrapper
215. return self.admin_view(view, cacheable)(*args, **kwargs) File "/usr/lib/python2.6/site-packages/django/utils/decorators.py" in
_wrapped_view
99. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py" in
_wrapped_view_func
52. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py" in inner
197. return self.login(request) File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py" in
_wrapped_view_func
52. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py" in login
330. return login(request, **defaults) File "/usr/lib/python2.6/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
75. return view(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/utils/decorators.py" in
_wrapped_view
99. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/views/decorators/cache.py" in
_wrapped_view_func
52. response = view_func(request, *args, **kwargs) File "/usr/lib/python2.6/site-packages/django/contrib/auth/views.py" in login
36. if form.is_valid(): File "/usr/lib/python2.6/site-packages/django/forms/forms.py" in is_valid
129. return self.is_bound and not bool(self.errors) File "/usr/lib/python2.6/site-packages/django/forms/forms.py" in errors
121. self.full_clean() File "/usr/lib/python2.6/site-packages/django/forms/forms.py" in full_clean
274. self._clean_form() File "/usr/lib/python2.6/site-packages/django/forms/forms.py" in
_clean_form
300. self.cleaned_data = self.clean() File "/usr/lib/python2.6/site-packages/django/contrib/admin/forms.py" in clean
28. self.user_cache = authenticate(username=username, password=password) File "/usr/lib/python2.6/site-packages/django/contrib/auth/__init__.py" in authenticate
49. user = backend.authenticate(**credentials) File "/usr/lib/python2.6/site-packages/django/contrib/auth/backends.py" in authenticate
16. user = UserModel._default_manager.get_by_natural_key(username) File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py" in get_by_natural_key
167. return self.get(**{self.model.USERNAME_FIELD: username}) File "/usr/lib/python2.6/site-packages/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in get
301. num = len(clone) File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in
__len__
77. self._fetch_all() File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in
_fetch_all
854. self._result_cache = list(self.iterator()) File "/usr/lib/python2.6/site-packages/django/db/models/query.py" in iterator
220. for row in compiler.results_iter(): File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in results_iter
709. for rows in self.execute_sql(MULTI): File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
781. cursor = self.connection.cursor() File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py" in cursor
157. cursor = self.make_debug_cursor(self._cursor()) File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py" in _cursor
129. self.ensure_connection() File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py" in ensure_connection
124. self.connect() File "/usr/lib/python2.6/site-packages/django/db/utils.py" in __exit__
99. six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py" in ensure_connection
124. self.connect() File "/usr/lib/python2.6/site-packages/django/db/backends/__init__.py" in connect
112. self.connection = self.get_new_connection(conn_params) File "/usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py" in get_new_connection
346. conn = Database.connect(**conn_params)
Exception Type: OperationalError at /admin/ Exception Value: unable to open database file
settings.py database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'pymail',
'USER': 'pymail',
'PASSWORD': 'removed',
'HOST': 'removed',
'PORT': '3306',
}
}

django-reversion: get_for_object() throws database error "'<db_name>.django_content_type' doesn't exist"

During my first attempt at using django-reversion, I was evaluating it to see if I can do certain basic version retrieval operations on my model:
I'm unable to retrieve a list of prior versions of specific model after saving a change to a specific field within scope of reversion as shown below. I get the following error in stack trace when attempting a reversion.get_for_object():
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
Django: v1.3.1
django-reversion: v1.5.7
Installed django-reversion and managed a syncdb successfully:
bash-3.2$ python manage.py syncdb
Creating tables ...
Creating table reversion_revision
Creating table reversion_version
Installing custom SQL ...
Installing indexes ...
No fixtures found.
Added reversion specific settings in settings.py:
INSTALLED_APPS = (
# 'django.contrib.auth',
# 'django.contrib.contenttypes',
# 'django.contrib.sessions',
# 'django.contrib.sites',
# 'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.staticfiles',
'collabgrid.testmatrix',
'collabgrid.testcase',
'collabgrid.status',
'reversion',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'reversion.middleware.RevisionMiddleware',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'PVTestMatrix',
...}
}
models.py:
...
class Testmatrix(models.Model):
testmatrixid = models.AutoField(primary_key=True, db_column='TestMatrixId')
platform = models.CharField(max_length=60, db_column='Platform', blank=True)
...
class Meta:
db_table = u'TestMatrix'
def __str__(self):
return '%s__%s__%s' % (self.productid, self.testmatrixid, self.owner)
...
view.py snippet:
from collabgrid.testmatrix.models import Testmatrix
import reversion
reversion.register(Testmatrix)
tm=Testmatrix.objects.get(pk=729)
with reversion.create_revision():
tm.platform="AAA"
tm.save()
version_list = reversion.get_for_object(tm)
stack trace:
>>> from collabgrid.testmatrix.models import Testmatrix
>>> import reversion
>>>
>>> reversion.register(Testmatrix)
>>> tm=Testmatrix.objects.get(pk=729)
>>> with reversion.create_revision():
... tm.platform="AAA"
... tm.save()
...
Traceback (most recent call last):
File "<console>", line 3, in <module>
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 290, in __exit__
self._context_manager.end()
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 176, in end
in manager_context.iteritems()
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 175, in <genexpr>
for obj, data
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 602, in <lambda>
version_data = lambda: adapter.get_version_data(instance, VERSION_CHANGE, self._revision_context_manager._db)
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 97, in get_version_data
content_type = ContentType.objects.db_manager(db).get_for_model(obj)
File "/Library/Python/2.6/site-packages/django/contrib/contenttypes/models.py", line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "/Library/Python/2.6/site-packages/django/db/models/manager.py", line 135, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 378, in get_or_create
return self.get(**lookup), False
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 344, in get
num = len(clone)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
>>> version_list = reversion.get_for_object(tm)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 527, in get_for_object
return self.get_for_object_reference(obj.__class__, obj.pk, db)
File "/Library/Python/2.6/site-packages/reversion/revisions.py", line 506, in get_for_object_reference
content_type = ContentType.objects.db_manager(db).get_for_model(model)
File "/Library/Python/2.6/site-packages/django/contrib/contenttypes/models.py", line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
File "/Library/Python/2.6/site-packages/django/db/models/manager.py", line 135, in get_or_create
return self.get_query_set().get_or_create(**kwargs)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 378, in get_or_create
return self.get(**lookup), False
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 344, in get
num = len(clone)
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 82, in __len__
self._result_cache = list(self.iterator())
File "/Library/Python/2.6/site-packages/django/db/models/query.py", line 273, in iterator
for row in compiler.results_iter():
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 680, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Python/2.6/site-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Python/2.6/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/Library/Python/2.6/site-packages/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
DatabaseError: (1146, "Table 'pvtestmatrix.django_content_type' doesn't exist")
Am I using reversion correctly here? By running "reversion.get_for_object(tm)" I'm expecting to see a list containing at least the last saved version when issuing "tm.save()" in previous step.
Not sure if this error is specific to reversion handling as I'm able to commit changes to models I would normally without using reversion. Thanks in advance.
Your django_content_type table doesn't exist because django.contrib.contenttypes is commented out in your INSTALLED_APPS. Uncomment it (remove the #) and run syncdb again.