Jump to content

Django and MySQL configuration problem


Recommended Posts

I am having a problem getting Python/Django and MySQL to place nice together. I got the database set up (correctly, I believe). If I do not set the database engine in the settings.py file, most of my views work properly. If I try to access a view that requires the database, I get a nice Django exception page telling me that I did not set the database engine, which is expected. If I set the database engine as follows: (password line omitted)

DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'ado_mssql'.

DATABASE_NAME = 'aboyce_klickfu' # Or path to database file if using sqlite3.

DATABASE_USER = 'aboyce_klickfu' # Not used with sqlite3.

 

I just get a 500 error on all my pages telling me that the wsgi script threw an exception, but no details as to what the actual problem is.

 

CPanel username: aboyce

Site: www.klickfu.heliohost.org

 

Any help would be appreciated.

Regards,

Alex Boyce

Link to comment
Share on other sites

Don't do double posts. I think you did mistakenly. Admin delete one of the posts

http://www.helionet.org/index/index.php?showtopic=10011

 

 

It was an accident. My browser appeared hung, so I cancelled it and clicked post a second time. I couldn't find a way to delete the post myself.

 

UPDATE: I did get past the exception. I was missing an import line in the settings.py file. Now the pages load, but if I need to access the database, it still says that the database ENGINE is not configured. I am missing something simple. Can some please show me a working settings.py file that points to a MySQL database?

Link to comment
Share on other sites

Please post the stack trace.

 

Here is a link that will show all the info about the error: Admin Page

 

 

Stack Trace:

Environment:

 

 

Request Method: GET

Request URL: http://www.klickfu.com/admin/

 

Django Version: 1.3

Python Version: 2.7.1

Installed Applications:

['django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.admin',

'django.contrib.admindocs',

'promos']

Installed Middleware:

('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.middleware.doc.XViewMiddleware')

 

 

Traceback:

File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response

178. response = middleware_method(request, response)

File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response

36. request.session.save()

File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save

56. session_key = self.session_key,

File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session_key

175. self._session_key = self._get_new_session_key()

File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_new_session_key

167. if not self.exists(session_key):

File "/usr/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in exists

29. Session.objects.get(session_key=session_key)

File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py" in get

132. return self.get_query_set().get(*args, **kwargs)

File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in get

344. num = len(clone)

File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__

82. self._result_cache = list(self.iterator())

File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator

273. for row in compiler.results_iter():

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter

680. for rows in self.execute_sql(MULTI):

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql

725. sql, params = self.as_sql()

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in as_sql

59. out_cols = self.get_columns(with_col_aliases)

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in get_columns

188. col_aliases)

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in get_default_columns

276. r = '%s.%s' % (qn(alias), qn2(field.column))

File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in quote_name_unless_alias

43. r = self.connection.ops.quote_name(name)

File "/usr/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py" in complain

15. raise ImproperlyConfigured("You haven't set the database ENGINE setting yet.")

 

Exception Type: ImproperlyConfigured at /admin/

Exception Value: You haven't set the database ENGINE setting yet.

 

Settings:

 

USE_L10N False

USE_THOUSAND_SEPARATOR False

LANGUAGE_CODE 'en-us'

ROOT_URLCONF 'urls'

MANAGERS (('Alex Boyce', 'alex@klickfu.com'),)

DEFAULT_CHARSET 'utf-8'

STATIC_ROOT ''

TEST_DATABASE_CHARSET None

MESSAGE_STORAGE 'django.contrib.messages.storage.user_messages.LegacyFallbackStorage'

DATABASE_HOST ''

IGNORABLE_404_STARTS ('/cgi-bin/', '/_vti_bin', '/_vti_inf')

SEND_BROKEN_LINK_EMAILS False

URL_VALIDATOR_USER_AGENT 'Django/1.3 (http://www.djangoproject.com)'

STATICFILES_FINDERS ('django.contrib.staticfiles.finders.FileSystemFinder',

'django.contrib.staticfiles.finders.AppDirectoriesFinder')

SESSION_COOKIE_DOMAIN None

SESSION_COOKIE_NAME 'sessionid'

COMMENTS_MODERATORS_GROUP None

TIME_INPUT_FORMATS ('%H:%M:%S', '%H:%M')

DATABASES {'default': {'ENGINE': 'django.db.backends.mysql',

'HOST': '',

'NAME': 'aboyce_klickfu',

'PASSWORD': '********************',

'PORT': '',

'USER': 'aboyce_klickfu'}}

TEST_DATABASE_NAME None

FILE_UPLOAD_PERMISSIONS None

FILE_UPLOAD_HANDLERS ('django.core.files.uploadhandler.MemoryFileUploadHandler',

'django.core.files.uploadhandler.TemporaryFileUploadHandler')

DEFAULT_CONTENT_TYPE 'text/html'

APPEND_SLASH True

LOCALE_PATHS ()

DATABASE_ROUTERS []

YEAR_MONTH_FORMAT 'F Y'

STATICFILES_STORAGE 'django.contrib.staticfiles.storage.StaticFilesStorage'

CACHES {'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',

'LOCATION': ''}}

SERVER_EMAIL 'root@localhost'

SESSION_COOKIE_PATH '/'

IGNORABLE_404_ENDS ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi', 'favicon.ico', '.php')

MIDDLEWARE_CLASSES ('django.middleware.common.CommonMiddleware',

'django.contrib.sessions.middleware.SessionMiddleware',

'django.contrib.auth.middleware.AuthenticationMiddleware',

'django.middleware.doc.XViewMiddleware')

USE_I18N True

THOUSAND_SEPARATOR ','

SECRET_KEY '********************'

LANGUAGE_COOKIE_NAME 'django_language'

FILE_UPLOAD_TEMP_DIR None

TRANSACTIONS_MANAGED False

LOGGING_CONFIG 'django.utils.log.dictConfig'

TEMPLATE_LOADERS ('django.template.loaders.filesystem.load_template_source',

'django.template.loaders.app_directories.load_template_source')

FIRST_DAY_OF_WEEK 0

TEMPLATE_DEBUG True

AUTHENTICATION_BACKENDS ('django.contrib.auth.backends.ModelBackend',)

TEST_DATABASE_COLLATION None

FORCE_SCRIPT_NAME None

CACHE_BACKEND 'locmem://'

SESSION_COOKIE_SECURE False

CSRF_COOKIE_DOMAIN None

FILE_CHARSET 'utf-8'

DEBUG True

SESSION_FILE_PATH None

DEFAULT_FILE_STORAGE 'django.core.files.storage.FileSystemStorage'

INSTALLED_APPS ['django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.admin',

'django.contrib.admindocs',

'promos']

LANGUAGES (('ar', 'Arabic'),

('az', 'Azerbaijani'),

('bg', 'Bulgarian'),

('bn', 'Bengali'),

('bs', 'Bosnian'),

('ca', 'Catalan'),

('cs', 'Czech'),

('cy', 'Welsh'),

('da', 'Danish'),

('de', 'German'),

('el', 'Greek'),

('en', 'English'),

('en-gb', 'British English'),

('es', 'Spanish'),

('es-ar', 'Argentinian Spanish'),

('es-mx', 'Mexican Spanish'),

('es-ni', 'Nicaraguan Spanish'),

('et', 'Estonian'),

('eu', 'Basque'),

('fa', 'Persian'),

('fi', 'Finnish'),

('fr', 'French'),

('fy-nl', 'Frisian'),

('ga', 'Irish'),

('gl', 'Galician'),

('he', 'Hebrew'),

('hi', 'Hindi'),

('hr', 'Croatian'),

('hu', 'Hungarian'),

('id', 'Indonesian'),

('is', 'Icelandic'),

('it', 'Italian'),

('ja', 'Japanese'),

('ka', 'Georgian'),

('km', 'Khmer'),

('kn', 'Kannada'),

('ko', 'Korean'),

('lt', 'Lithuanian'),

('lv', 'Latvian'),

('mk', 'Macedonian'),

('ml', 'Malayalam'),

('mn', 'Mongolian'),

('nl', 'Dutch'),

('no', 'Norwegian'),

('nb', 'Norwegian Bokmal'),

('nn', 'Norwegian Nynorsk'),

('pa', 'Punjabi'),

('pl', 'Polish'),

('pt', 'Portuguese'),

('pt-br', 'Brazilian Portuguese'),

('ro', 'Romanian'),

('ru', 'Russian'),

('sk', 'Slovak'),

('sl', 'Slovenian'),

('sq', 'Albanian'),

('sr', 'Serbian'),

('sr-latn', 'Serbian Latin'),

('sv', 'Swedish'),

('ta', 'Tamil'),

('te', 'Telugu'),

('th', 'Thai'),

('tr', 'Turkish'),

('uk', 'Ukrainian'),

('ur', 'Urdu'),

('vi', 'Vietnamese'),

('zh-cn', 'Simplified Chinese'),

('zh-tw', 'Traditional Chinese'))

DATABASE_ENGINE ''

DATABASE_NAME ''

COMMENTS_FIRST_FEW 0

PREPEND_WWW False

SESSION_COOKIE_HTTPONLY False

DATABASE_PORT ''

DEBUG_PROPAGATE_EXCEPTIONS False

MONTH_DAY_FORMAT 'F j'

LOGIN_URL '/accounts/login/'

SESSION_EXPIRE_AT_BROWSER_CLOSE False

TIME_FORMAT 'P'

DATE_INPUT_FORMATS ('%Y-%m-%d',

'%m/%d/%Y',

'%m/%d/%y',

'%b %d %Y',

'%b %d, %Y',

'%d %b %Y',

'%d %b, %Y',

'%B %d %Y',

'%B %d, %Y',

'%d %B %Y',

'%d %B, %Y')

CSRF_COOKIE_NAME 'csrftoken'

EMAIL_HOST_PASSWORD '********************'

PASSWORD_RESET_TIMEOUT_DAYS '********************'

CACHE_MIDDLEWARE_ALIAS 'default'

SESSION_SAVE_EVERY_REQUEST False

ADMIN_MEDIA_PREFIX '/media/'

NUMBER_GROUPING 0

SESSION_ENGINE 'django.contrib.sessions.backends.db'

CSRF_FAILURE_VIEW 'django.views.csrf.csrf_failure'

COMMENTS_SKETCHY_USERS_GROUP None

LOGIN_REDIRECT_URL '/accounts/profile/'

LOGGING {'disable_existing_loggers': False,

'handlers': {'mail_admins': {'class': 'django.utils.log.AdminEmailHandler',

'level': 'ERROR'}},

'loggers': {'django.request': {'handlers': ['mail_admins'],

'level': 'ERROR',

'propagate': True}},

'version': 1}

CACHE_MIDDLEWARE_KEY_PREFIX ''

PROJECT_PATH '/home/aboyce/public_html'

TEMPLATE_STRING_IF_INVALID ''

COMMENTS_ALLOW_PROFANITIES False

LOGOUT_URL '/accounts/logout/'

EMAIL_USE_TLS False

TEMPLATE_DIRS ('/home/aboyce/public_html/templates',)

FIXTURE_DIRS ()

EMAIL_HOST 'localhost'

DATE_FORMAT 'N j, Y'

MEDIA_ROOT '/home/aboyce/public_html/static/media/'

ADMINS (('Alex Boyce', 'alex@klickfu.com'),)

FORMAT_MODULE_PATH None

DEFAULT_FROM_EMAIL 'webmaster@localhost'

STATICFILES_DIRS ()

MEDIA_URL 'http://www.klickfu.heliohost.org/static/media/'

DATETIME_FORMAT 'N j, Y, P'

EMAIL_SUBJECT_PREFIX '[Django] '

SITE_ID 1

DISALLOWED_USER_AGENTS ()

ALLOWED_INCLUDE_ROOTS ()

DECIMAL_SEPARATOR '.'

SHORT_DATE_FORMAT 'm/d/Y'

DATABASE_USER ''

TEST_RUNNER 'django.test.simple.DjangoTestSuiteRunner'

TIME_ZONE 'America/Chicago'

FILE_UPLOAD_MAX_MEMORY_SIZE 2621440

EMAIL_BACKEND 'django.core.mail.backends.smtp.EmailBackend'

DEFAULT_TABLESPACE ''

TEMPLATE_CONTEXT_PROCESSORS ('django.contrib.auth.context_processors.auth',

'django.core.context_processors.debug',

'django.core.context_processors.i18n',

'django.core.context_processors.media',

'django.core.context_processors.static',

'django.contrib.messages.context_processors.messages')

SESSION_COOKIE_AGE 1209600

SETTINGS_MODULE 'settings'

USE_ETAGS False

LANGUAGES_BIDI ('he', 'ar', 'fa')

DEFAULT_INDEX_TABLESPACE ''

INTERNAL_IPS ()

STATIC_URL None

EMAIL_PORT 25

SHORT_DATETIME_FORMAT 'm/d/Y P'

ABSOLUTE_URL_OVERRIDES {}

DATABASE_OPTIONS {}

CACHE_MIDDLEWARE_SECONDS 600

BANNED_IPS ()

DATETIME_INPUT_FORMATS ('%Y-%m-%d %H:%M:%S',

'%Y-%m-%d %H:%M',

'%Y-%m-%d',

'%m/%d/%Y %H:%M:%S',

'%m/%d/%Y %H:%M',

'%m/%d/%Y',

'%m/%d/%y %H:%M:%S',

'%m/%d/%y %H:%M',

'%m/%d/%y')

DATABASE_PASSWORD '********************'

ADMIN_FOR ()

COMMENTS_BANNED_USERS_GROUP None

EMAIL_HOST_USER ''

PROFANITIES_LIST '********************'

 

 

 

 

Link to comment
Share on other sites

Guest Geoff

Try using the following configuration instead (change the values to the appropriate configuration):

 

DATABASE_NAME = '' # Or path to database file if using sqlite3.

DATABASE_USER = '' # Not used with sqlite3.

DATABASE_PASSWORD = '' # Not used with sqlite3.

DATABASE_ENGINE = 'mysql' #mysql, etc

DATABASE_HOST = 'localhost'

DATABASE_PORT = '3306'

Link to comment
Share on other sites

Try using the following configuration instead (change the values to the appropriate configuration):

 

DATABASE_NAME = '' # Or path to database file if using sqlite3.

DATABASE_USER = '' # Not used with sqlite3.

DATABASE_PASSWORD = '' # Not used with sqlite3.

DATABASE_ENGINE = 'mysql' #mysql, etc

DATABASE_HOST = 'localhost'

DATABASE_PORT = '3306'

 

I have tried that. I started with the old style configuration and during my research, I came upon the new style and tried it. I have used either and both at the same time. They all result in the same thing.

Link to comment
Share on other sites

Alright, I have figured out a few things. First, the reason adding "import django.db.backends" resolved the exception was because it was executed before I set the DATABASES variable so it defaulted to not set. So it didn't solve the problem, it masked it.

Second, I can connect to my MySQL database from a simple python script in the cgi-bin folder when it uses version 2.4 (the default). But when I use Python 2.7 is fails to import MySQLdb (which would explain my Django exceptions). I looked in the site-packages folders for both, /usr/lib/python2.4/site-packages and /usr/local/lib/python2.7/site-packages, and only Python 2.4 has the MySQL package.

 

Is MySQL supported with DJango on Heliohost? It doesn't appear to be installed.

 

Also, why is the path for Python 2.7 /usr/local/lib and for Python 2.4 it is /usr/lib. Is that the problem?

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...