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

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.

Related

Django Python LoadData: Error Problem Installing Fixture

First I have migrate and makemigrations and then I have dump data with this command:
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > dvvv.json
I have tried to flush the database but when I execute python manage.py loaddata dvvv.json the following error occurs:
pymysql.err.ProgrammingError: (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 78, in handle
self.loaddata(fixture_labels)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 123, in loaddata
self.load_label(fixture_label)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/management/commands/loaddata.py", line 190, in load_label
obj.save(using=self.using)
File "/root/Django/my_env/lib/python3.7/site-packages/django/core/serializers/base.py", line 223, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 778, in save_base
force_update, using, update_fields,
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 859, in _save_table
forced_update)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/base.py", line 912, in _do_update
return filtered._update(values) > 0
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/query.py", line 802, in _update
return query.get_compiler(self.db).execute_sql(CURSOR)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql
cursor = super().execute_sql(result_type)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/root/Django/my_env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 73, in execute
return self.cursor.execute(query, args)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 148, in execute
result = self._query(query)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/cursors.py", line 310, in _query
conn.query(q)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 775, in _read_query_result
result.read()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/connections.py", line 725, in _read_packet
packet.raise_for_error()
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "/root/Django/my_env/lib/python3.7/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.ProgrammingError: Problem installing fixture '/root/Django/dvvv.json': Could not load Prilert.ConfirmationEmail(pk=137): (1146, "Table 'webcnytc_prilert_tool.Prilert_confirmationemail' doesn't exist")

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: 1215, 'Cannot add foreign key constraint' on model with only one field

I have a Salad model:
class Salad(models.Model):
some_field = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
No matter how I call the class, the single field, what models I put instead of Profile, or whichever on_delete option I choose. I systematically get the error:
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
The error log:
Traceback (most recent call last):
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
Applying playerdata.0053_auto_20180724_1943... return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\django_manage.py", line 52, in <module>
run_command()
File "C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:/Python/DjangoProjects/rolegate\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 90, in __exit__
self.execute(sql)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\base\schema.py", line 117, in execute
cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\backends\mysql\base.py", line 71, in execute
return self.cursor.execute(query, args)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\Users\Div-o\AppData\Local\Programs\Python\Python35-32\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')
Normally it is caused by the fact that your two related tables are not using InnoDB and at least one of them uses MyISAM engine instead.
The problem is Foreign keys are not supported on MyISAM.
Here is a related Django ticket #26777.
Since this is entirely related to MYSQL and not a Django specific, I will link this thread that could potentially help you,
Converting Tables from MyISAM to InnoDB
FUN FACT
I'm not the one that took care of this Django ticket even if the names are similar. #SimonCharette is.

Celery Django Error in timer: OperationalError(2006, 'MySQL server has gone away')

I am using Django and celery to run some tasks. i have 6 workers with concurrency 1, and different tasks are sent to different workers. one of witch raises a Error in timer: OperationalError(2006, 'MySQL server has gone away').
system runs normally until something happens and worker stops running tasks until manually restarted.
I have:
Django==1.6
celery==3.1.5
django-celery==3.1.1
MySQL-python==1.2.4
kombu==3.0.6
Traceback:
[2015-12-10 09:50:43,300: ERROR/MainProcess] Error in timer: OperationalError(2006, 'MySQL server has gone away')
Traceback (most recent call last):
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/kombu/async/timer.py", line 171, in apply_entry
entry()
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/kombu/async/timer.py", line 64, in __call__
return self.fun(*self.args, **self.kwargs)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/kombu/async/timer.py", line 132, in _reschedules
return fun(*args, **kwargs)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/celery/events/snapshot.py", line 73, in capture
self.state.freeze_while(self.shutter, clear_after=self.clear_after)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/celery/events/state.py", line 428, in freeze_while
return fun(*args, **kwargs)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/celery/events/snapshot.py", line 70, in shutter
self.on_shutter(self.state)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/snapshot.py", line 139, in on_shutter
_handle_tasks()
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/snapshot.py", line 135, in _handle_tasks
self.handle_task(task)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/snapshot.py", line 82, in handle_task
(task.worker.hostname, task.worker),
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/snapshot.py", line 72, in handle_worker
defaults={'last_heartbeat': self.get_heartbeat(worker)},
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/managers.py", line 87, in update_or_create
return get_queryset(self).update_or_create(**kwargs)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/djcelery/managers.py", line 70, in update_or_create
obj, created = self.get_or_create(**kwargs)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 373, in get_or_create
return self.get(**lookup), False
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__
self._fetch_all()
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all
self._result_cache = list(self.iterator())
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 710, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 781, in execute_sql
cursor.execute(sql, params)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/opt/virtualenvs/simocEnv/local/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')
if you use flask, you can use db.session.close() before some CRUD operator.
Reference:
OperationalError: (2006, 'MySQL server has gone away after upgrading from celery 4.1.0 to 4.2.0')
OperationalError: (2006, 'MySQL server has gone away')

Getting ""Duplicate column name" error in Django for no apparent reason

I've looked here and through Google, and found nothing that seems to describe what I'm seeing. I'm using Django 1.7 with Python 3.4.
ETA: I'm using MySQL 5.6.17
I have the following model (unrelated fields left out):
class Location(models.Model):
location_type = models.CharField(max_length=5,
choices=constants.LocationTypes.LOCATION_CHOICES
)
parent = models.ForeignKey("Location", blank=True, null=True, related_name='location_parent')
room = models.ForeignKey("Location", blank=True, null=True, related_name='location_room')
There are no other instances of "room" anywhere else in models.py except for a comment.
It worked fine until I added the room field (adding the related _name to parent at the same time). Now when I try to run the migration, I get the following:
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
pymysql.err.InternalError: (1060, "Duplicate column name 'room_id'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:/Users/Phoenix/PycharmProjects/gamecon/manage.py", line 10, in <module> execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 377, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 338, in execute output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 160, in handle executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 63, in migrate self.apply_migration(migration, fake=fake)
File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 97, in apply_migration migration.apply(project_state, schema_editor)
File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 107, in apply operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py", line 37, in database_forwards field,
File "C:\Python34\lib\site-packages\django\db\backends\mysql\schema.py", line 42, in add_field super(DatabaseSchemaEditor, self).add_field(model, field)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 390, in add_field self.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\schema.py", line 99, in execute cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 81, in execute return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python34\lib\site-packages\django\utils\six.py", line 549, in reraise raise value.with_traceback(tb)
File "C:\Python34\lib\site-packages\django\db\backends\utils.py", line 65, in execute return self.cursor.execute(sql, params)
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", line 128, in execute return self.cursor.execute(query, args)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 132, in execute result = self._query(query)
File "C:\Python34\lib\site-packages\pymysql\cursors.py", line 271, in _query conn.query(q)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 726, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 861, in _read_query_result result.read()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1064, in read first_packet = self.connection._read_packet()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 826, in _read_packet packet.check_error()
File "C:\Python34\lib\site-packages\pymysql\connections.py", line 370, in check_error raise_mysql_exception(self._data)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 116, in raise_mysql_exception _check_mysql_exception(errinfo)
File "C:\Python34\lib\site-packages\pymysql\err.py", line 112, in _check_mysql_exception raise InternalError(errno, errorvalue)
django.db.utils.InternalError: (1060, "Duplicate column name 'room_id'")
Can someone please tell me what I'm missing here?
Made answer from comment
if you are doing ForeignKey on the model itself you should do it like this
models.ForeignKey("self", blank=True, null=True, related_name='location_parent')