django manage.py runserver error Unknown system variable 'innodb_strict_mode'" - mysql

I'm using python 2.7.14, django 1.11 and mysql 5.7 to my local server and it work fine until i tried to connect in our external mysql 5.1 database and got below error when checking my connection (python manage.py runserver). I suspected because external Mysql is version 5.1. Below is my database setting and error message:
default':
{
'ENGINE': 'django.db.backends.mysql',
#'NAME': os.path.join(BASE_DIR, 'db.mysql'),
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME': 'Mfg',
'USER': 'arastra',
'PASSWORD': '', #no password
'HOST': 'localhost',
'PORT': '3356', # Tunnel set-up.
File "C:\Python27\Lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
return self.cursor.execute(query, args)
File "C:\Python27\Lib\site-packages\MySQLdb\cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\Lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
django.db.utils.OperationalError: (1193, "Unknown system variable 'innodb_strict_mode'")

Related

I have installed MySQL for Python . Now I try to connect to the MySQL Community Server on my local machine, using this code:

DATABASES = {
'default': {
'NAME': "food",
'ENGINE': 'django.db.backends.mysql',
'HOST': 'localhost',
'USER': 'root',
'PASSWORD': 'groot',
This code fails with this error:
...
connection = Database.connect(**conn_params)
File "C:\Users\mona\Downloads\food-ordering-system-master\food-ordering-system-master\food-ordering-system\env\lib\site-packages\MySQLdb_init_.py", line 84, in Connect
return Connection(*args, **kwargs)
File "C:\Users\mona\Downloads\food-ordering-system-master\food-ordering-system-master\food-ordering-system\env\lib\site-packages\MySQLdb\connections.py", line 179, in init
super(Connection, self).init(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on 'localhost' (10061)")

Requested setting DATABASES, but settings are not configured error in my Django project

I am attempting to change my database settings in my django project from sqlite3 to mysql.
I edited the database object in my settings.py file :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Identity',
'USER' : 'root',
'PASSWORD': ''
}
}
I ran django-admin dbshell and got this error :
File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/init.py",
line 39, in _setup
% (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting
DATABASES, but settings are not configured. You must either define the
environment variable DJANGO_SETTINGS_MODULE or call
settings.configure() before accessing settings.
I followed the instruction from this answer to use settings.configure()
from django.conf import settings
settings.configure()
It returned this message :
Traceback (most recent call last): File "", line 1, in
File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/init.py",
line 63, in configure
raise RuntimeError('Settings already configured.') RuntimeError: Settings already configured.
When I ran python3 manage.py shell it gives me this error :
File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/db/backends/mysql/base.py",
line 28, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: No module named 'MySQLdb'
All I want to do is use mySql instead of sqlite db.
How do I do this ?
It seems MySQLdb packages are missing,
can you check this package are installed
apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev
In your virtual environment,conform mysql client installed
pip install mysqlclient
then do the mysql configuration in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_db',#database name
'HOST': '127.0.0.1',#
'PORT': '3306',#mysql port
'USER': 'root',#mysql username
'PASSWORD': 'test123',#mysql password
'OPTIONS': {
'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
'charset': 'utf8mb4',
}
}
}

django-balanced - Database Error

I'm trying to install the django-balanced app in my project and I'm getting an error.
I did the following as the readme file says:
#Add to settings
import os
BALANCED = {
'API_KEY': os.environ.get('BALANCED_API_KEY'),
}
INSTALLED_APPS = (
...
'django.contrib.admin', # if you want to use the admin interface
'django_balanced',
...
)
#ran the following on my project root folder
BALANCED_API_KEY=YOUR_API_KEY django-admin.py syncdb #replacing the YOUR_API_KEY with my key
When I do this, I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
When I do the python manage.py syncdb, I get no errors with the database. I might be missing something in the database setting that the readme file does not mention. Thanks in advance
here is my database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'payload', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'pass123', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
You can also type the following command
BALANCED_API_KEY=YOUR_API_KEY python manage.py syncdb
You need to set the DJANGO_SETTINGS_MODULE:
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings

MySQLdb in Python: "Can't connect to MySQL server on 'localhost'"

I have installed MySQLdb for Python and I am able to import MySQLdb. Now I try to connect to the MySQL Community Server on my local machine, using this code:
db=MySQLdb.connect(
host="localhost",
user="br_admin",
passwd="blabla",
db="br_brain"
)
This code fails with this error:
Traceback (most recent call last):
File "<pyshell#22>", line 5, in <module>
db="brainse_brain"
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
How do I resolve this error?
Make sure to provide the proper host and port:
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'yourdbname',
'USER': 'root',
'PASSWORD': 'your password',
'HOST': '127.0.0.1',
'PORT': '3306',
},
This is my settings.py file config for my django app.
Same for you please take host "127.0.0.1" and port "3306".
This might solve your problem.
And for python idle I've tested like...
>>> import MySQLdb
>>> Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="yoruname", passwd="yourpwd", db="test")
>>> Cursor = Con.cursor()
>>> sql = "SELECT * FROM test.testing"
>>> Cursor.execute(sql)
2L
I had the same trouble too, I'm working on a Windows of 64 bits, and the solution just was changing the host variable value. I had set "localhost" when the correct value have to be "127.0.0.1". However, when I'm working on Windows of 32 bits. I can set "localhost" or "127.0.0.1" in the host variable value and no matter, my django's project runs perfectly.
This will work fine :
db = MySQLdb.connect(host="127.0.0.1",user="db_username",passwd="db_password",db="db_name")
or
db= MySQLdb.connect("127.0.0.1","db_username","db_password","db_name")
In Windows 32, if you set host as 127.0.01 it gives the down error:
OperationalError: (2005, "Unknown MySQL server host '127.0.01' (0)")
But if you set host as 127.0.0.1 then you get no error.
If you are using windows you should specify the IP to "127.0.0.1", using "localhost" will give you that error 2003. On Ubuntu I had no problem.
1.Go to MySQL workbench
2.On the task bar above, click on server->and then click on Startup/Shutdown
3.On the screen, click on Start the server and you will get logs of server starting and running
- DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dataflair',
'USER':'root',
'PASSWORD':'',
'HOST':'127.0.0.1',
'PORT':'3306',
'OPTIONS':{
'init_command':"SET sql_mode=STRICT_TRANS_TABLES" }

Django tutorial says I haven't set DATABASE_ENGINE setting yet... but I have

I'm working through the Django tutorial and receiving the following error when I run the initial python manage.py syncdb:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 362 in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 222, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.6/site-packages/django/core/management/commands/syncdb.py", line 49, in handle_noargs
cursor = connection.cursor()
File "/Library/Python/2.6/site-packages/django/db/backends/dummy/base.py", line 15, in complain
raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet."
django.core.exceptions.ImproperlyConfigured: You haven't set the DATABASE_ENGINE setting yet.
My settings.py looks like:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'dj_tut', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
I'm guessing this is something simple, but why isn't it seeing the ENGINE setting?
It looks like you are using an earlier version of Django. That way of setting database configuration is from Django 1.2, but the error you are getting is from 1.1. If you are using version 1.1, use this version of the tutorial.
'ENGINE': 'mysql',
'NAME': 'dj_tut',
and you will want to set a user and password.
Same problem happened frequently to me and everytime the problem was cyclic dependencies between sttings.py and another module.
At command prompt you should write:
edit settings.py
then there will be a new module for editing your
settings.py