Error while connecting to SQL server through Django - django

In settings file, I have given SQL SERVER Database connection values like this.
DATABASES = {
'default': {
'NAME': 'AdventureWorks2014',
'ENGINE': 'sqlserver_ado',
'HOST': '127.0.0.1',
'USER': '',
'PASSWORD': '',
}
}
Versions:
Django v:1.11
Python v:2.7
django-mssql v:1.8
pip v:9.0
Development Platform:
Visual Studio
After the database connection values changes, I have used the command
python manage.py makemigrations
Here I got the error:
Executing manage.py makemigrations
Traceback (most recent call last):
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\manage.py", line 17, in
execute_from_command_line(sys.argv)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\core\management__init__.py", line 364, in execute_from_command_line
utility.execute()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\core\management__init__.py", line 338, in execute
django.setup()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\Lib\importlib__init__.py", line 37, in import_module
import(name)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\contrib\auth\models.py", line 4, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\contrib\auth\base_user.py", line 52, in
class AbstractBaseUser(models.Model):
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\base.py", line 124, in new
new_class.add_to_class('_meta', Options(meta, app_label))
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db__init__.py", line 33, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\utils.py", line 212, in getitem
conn = backend.DatabaseWrapper(db, alias)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\sqlserver_ado\base.py", line 184, in init
super(DatabaseWrapper, self).init(*args, **kwargs)
File "E:\Django Projects\DjangoMSSQLDatabaseConn\DjangoMSSQLDatabaseConn\VirtualEnv\lib\site-packages\django\db\backends\base\base.py", line 96, in init
self.client = self.client_class(self)
TypeError: Error when calling the metaclass bases
'NoneType' object is not callable
The interactive Python process has exited.
Can anyone help me solve this?

Related

python-django/python manage.py runserver error

I am trying to run the server using this command python manage.py runserver but i am getting this error even i have installed mysqlclient and mysql-python:
C:\Users\neethu\sencha\sencha-sdks\sencha_workspace\webapp>python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x0397EC70>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Python27\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 30, in <module>
'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: DLL load failed: %1 is not a valid Win32 application..
Did you install mysqlclient or MySQL-python?

django exception: libperconaserverclient.so.18: cannot open shared object file: No such file or directory

I am new to django.
I get this error when I update settings.py with database and run
$python2.7 manage.py migrate
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: libperconaserverclient.so.18: cannot open shared object file:
No such file or directory
Is it because of version of mysql ? if so which version should I use ?
$ python2.7 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libperconaserverclient.so.18: cannot open shared object file: No such file or directory
I am using RHEL 6.7, MySql Server version: 5.1.73 and Python 2.7.11
yum -y install mysql-devel
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so.18 /usr/lib
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so /usr/lib
Idconifg
done!

django unable to start runserver

unable to start C:\Python27\mysastha>python manage.py runserver
c:\python27\lib\site-packages\djangotoolbox-1.6.2-py2.7.egg\djangotoolbox\db\uti
ls.py:5: RemovedInDjango19Warning: django.utils.unittest will be removed in Djan
go 1.9.
from django.utils.unittest import skip
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 330, in execute_from_command_line
utility.execute()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 304, in execute
django.setup()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\__init__.py",
line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\registry.
py", line 108, in populate
app_config.import_models(all_models)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\config.py
", line 197, in import_models
self.models_module = import_module(models_module_name)
File "c:\python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\auth\m
odels.py", line 40, in <module>
class Permission(models.Model):
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 127, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 303, in add_to_class
value.contribute_to_class(cls, name)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\opti
ons.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\__init__.py
", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 238, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 127, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an av
ailable database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'django_mongodb_engine', u'mysql', u'oracle', u'postgresql_psycopg2', u'sql
ite3'
Error was: cannot import name decimal_to_string
Just follow the instructions in the trace back. you need django.db.backends.django_mongodb_engine as the engine. Not just django_mongodb_engine.
If you havent already you will probably need a couple dependencies for the engine to work. im on mobile and dont know what they are called at the moment for mongodb

django-rocket-engine is failing as GOOGLE_SQL_EXTRA_PATHS is missing

I have a django project that I am trying to deploy on GAE. However, When I add
from rocket_engine import on_appengine
in my settings.py file, my project starts crashing with this error message:
$ python manage.py runserver 0.0.0.0:8000
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, 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 261, in fetch_command
commands = get_commands()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/Users/koray/Dropbox/code/python/taxiweb/wtx/settings.py", line 65, in <module>
from rocket_engine import on_appengine
File "/Library/Python/2.7/site-packages/rocket_engine/__init__.py", line 91, in <module>
setup_appendine_sdk()
File "/Library/Python/2.7/site-packages/rocket_engine/__init__.py", line 56, in setup_appendine_sdk
sys.path.extend(dev_appserver.GOOGLE_SQL_EXTRA_PATHS)
AttributeError: 'module' object has no attribute 'GOOGLE_SQL_EXTRA_PATHS'
The change I have made in the settings file is
if on_appengine:
ROOT_URLCONF = 'urls'
DATABASES = {
'default': {
'ENGINE': 'rocket_engine.db.backends.cloudsql',
'INSTANCE': 'instance:name',
'NAME': 'database_name',
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
I am on a mac, django-rocket-engine is installed via pip. What am I missing here?

Django with GeoDjango on AWS EC2, Postgres Postgis on RDS

I'm trying to build an application with server code on AWS EC2 and the Spatial DB Postgis on RDS. I can access the Postgres from EC2 using command line:
psql --host=mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com --port=5432 --username=ec2 --password --dbname=mydb
mydb=>
I use GeoDjango on the EC2, and this is the setting for my DB:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'mydb',
'USER': 'ec2',
'PASSWORD': 'password',
'HOST': 'mydbpostgres.qazwsxedcrfv.us-west-1.rds.amazonaws.com',
'PORT': '5432',
}
}
But when I run migration, it gives my error like this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.6/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/usr/lib/python2.6/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/lib/python2.6/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "/usr/lib/python2.6/site-packages/django/contrib/admin/sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "/usr/lib/python2.6/site-packages/django/contrib/admin/forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "/usr/lib/python2.6/site-packages/django/contrib/auth/forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "/usr/lib/python2.6/site-packages/django/contrib/auth/models.py", line 48, in <module>
class Permission(models.Model):
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/usr/lib/python2.6/site-packages/django/db/models/base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/lib/python2.6/site-packages/django/db/models/options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/lib/python2.6/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/lib/python2.6/site-packages/django/db/utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 5, in <module>
from django.contrib.gis.db.backends.postgis.operations import PostGISOperations
File "/usr/lib/python2.6/site-packages/django/contrib/gis/db/backends/postgis/operations.py", line 8, in <module>
from django.contrib.gis.geometry.backend import Geometry
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/__init__.py", line 8, in <module>
module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
File "/usr/lib/python2.6/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geometry/backend/geos.py", line 1, in <module>
from django.contrib.gis.geos import (
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/__init__.py", line 7, in <module>
from .libgeos import geos_version, geos_version_info, GEOS_PREPARE
File "/usr/lib/python2.6/site-packages/django/contrib/gis/geos/libgeos.py", line 58, in <module>
lgeos = CDLL(lib_path)
File "/usr/lib64/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libgeos_c.so.1: cannot open shared object file: No such file or directory
It looks like I'm missing some libraries of postgis on my EC2. My question is, do I need to install a postgis instance on my ec2 so that my server can find all that necessary libs? Or how can I make my server to look for the libs on the RDS?
Thanks very much!
It looks like you're just missing the "geos" library. If you're running Amazon Linux, installing that is as simple as yum install geos. That library provides the file: /usr/lib/libgeos_c.so.1