Django app failed to connect with ms sql server 2014 - python

I am new in django,stuck on migration process, as a beginner can not find valuable information from error message. Need help about migration and db connection with application process.
pip list
Django (1.11.2)
django-mssql (1.8)
mysqlclient (1.3.10)
pip (9.0.1)
pytz (2017.2)
setuptools (28.8.0)
wheel (0.29.0)
Python 3.6.1
To install Python package manage for ms sql server used bellow command
pip install django-mssql
My app model is
from django.db import models
# Create your models here.
class Video(models.Model):
title=models.CharField("Title",max_length=250)
embed_code=models.TextField("Embed code")
My django application database settings is bellow
DATABASES = {
'default': {
'NAME': 'djangolife',# db name
'ENGINE': 'sqlserver_ado',
'HOST': 'DESKTOP-SVHDHF8\\MSSQLSERVER2014',#Sql server name
'USER': 'sa',
'PASSWORD': 'sa123',
}
}
Migration command
python manage.py makemigrations
After execute the above migration command get bellow errors
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 337, in execute
django.setup()
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models()
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 124, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\models\base.py", line 330, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\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:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\utils.py", line 212, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sqlserver_ado\base.py", line 184, in __init__
super(DatabaseWrapper, self).__init__(*args, **kwargs)
File "C:\Users\shamim\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\db\backends\base\base.py", line 96, in __init__
self.client = self.client_class(self)
TypeError: 'NoneType' object is not callable

I have the same issue and I found the reason is django-mssql support Django 1.8 but you are using Django 1.11. Please downgrade your Django version or wait until the latest version will be supported.

Related

I have installed mysqlclient , but not able to run server

I am a beginner in python and Django.
I would like to connect my Django project to MySQL database,I have installed mysqlclient
brew install mysql
pipenv install mysqlclient
but after changing the settings to:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'storefront',
'HOST': 'localhost',
'USER': 'root',
'PASSWORD': 'my_password',
}
}
I get an error for running server: (NameError: name '_mysql' is not defined)
source /Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/bin/activate
(base) niloufar#Niloufars-MacBook-Air site-functions % source /Users/niloufar/.local/share/virtualenvs/
site-functions-HFSltvjv/bin/activate
(site-functions) (base) niloufar#Niloufars-MacBook-Air site-functions % python manage.py runserver
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/niloufar/anaconda3/lib/python3.9/threading.py", line 973, in _bootstrap_inner
self.run()
File "/Users/niloufar/anaconda3/lib/python3.9/threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/core/management/__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/Users/niloufar/anaconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/models/base.py", line 141, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/models/base.py", line 369, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/models/options.py", line 235, in contribute_to_class
self.db_table, connection.ops.max_name_length()
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/utils.py", line 208, in create_connection
backend = load_backend(db["ENGINE"])
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
File "/Users/niloufar/anaconda3/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/Users/niloufar/.local/share/virtualenvs/site-functions-HFSltvjv/lib/python3.9/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
I have already checked the status of MySQL , and it is installed properly:
mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.29 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Also I have added the directory of MySQL to the PATH
echo $PATH
export PATH=$PATH:/opt/homebrew/opt/mysql
What's the problem then ?

Error when connecting Django project to mysql?

I'm using python 3 and I have tried to connect my Django project(django3) to MySQL but I keep getting this error even though I installed mysqlclient.
I get this error when I'm trying to connect to MySQL
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/models/options.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/utils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 21, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Make sure you are running the MySQL server on your machine.
Then find out you installed mysqlclient package on your system, you can install it using this command:
pip install mysqlclient
then add this config to your settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost'
'PORT': '3306',
}
}
According to https://github.com/Miserlou/lambda-packages You will get this error because there's no mysqlclient built for Python 3.7. Therefore you have to use pymysql.
I have figured out a way to fix this issue by,
First, you have to install pymysql
pip install pymysql
Then you have to add this code into init.py(or settings.py) file
import pymysql
pymysql.install_as_MySQLdb()
pymysql.version_info = (1, 3, 13, 'final', 0)

How to connect Django database to Sql server? [duplicate]

This Django project is working before I created another Django project on my computer. But today when I run the project it shows error message like that=>
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 114,
in populate
app_config.import_models()
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\options.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\__init__.py", line 28, in
__getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "Users..\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sql_server\pyodbc\base.py", line 12, in <module>
raise ImproperlyConfigured("Django %d.%d.%d is not supported." % VERSION[:3])
django.core.exceptions.ImproperlyConfigured: Django 3.0.1 is not supported.
What is mean Django 3.0.1 is not supported?
The sql_server package you're using isn't compatible with Django 3.0 or higher. It's not clear from your question which sql_server package you're using (is it django-pyodbc?) but most of the packages haven't added support for Django 3.0 yet.
Use a version of Django that is compatible with you django-pyodbc package (consult the documentation of the package, probably you should be using Django 2.1 or 2.2) or fork the package and modify it to support Django 3.0.
your problem is due to installing different version for your new project.you should use a different virtual environment for each project to avoiding this problems.
Can you please create virtualenv using python3.7.3 then install Django3 inside virtualenv. Because Django3 support only Pyth on3.6 and upper. Maybe some python version compatibility issue is there. for python version change please follow this link .. https://unix.stackexchange.com/questions/410579/change-the-python3-default-version-in-ubuntu

problem in connecting to mysql wamp and django?

I have a problem in connect mysql wamp to django using mysql connector
Hi , I Have a database in mysql and i want to connect it to django with mysqlconnector library :
I tries these :
Step 1 :
pip install mysqlconnector
Step 2 :
then change settings.py like this :
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'dbname',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
after this i run the server using :
python manage.py runserver
and at the end i got this error :
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x04B39C00>
Traceback (most recent call last):
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 112, in populate
app_config.import_models()
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py", line 101, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\base.py", line 305, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\utils.py", line 203, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mysql\connector\django\base.py", line 336, in __init__
super(DatabaseWrapper, self).__init__(*args, **kwargs)
File "C:\Users\p.mikaeil\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\db\backends\base\base.py", line 101, in __init__
self.client = self.client_class(self)
TypeError: 'NoneType' object is not callable
What can i do for this problem ?
any suggestions will be helpfull , thank you .
After searching and asking alot , i found the solution .
first i need to install build tools of microsoft .(this is available in microsoft visual studio package ) .
and then i downgrade my python version from 3.7.2 to 3.5.6 .
and then i use this command to install mysqlclient :
pip install --only-binary :all: mysqlclient
this is ok , and myproblem solved .

Can't migrate Sqllite to mysql in django

i have successfully installed mysqlclient in my django project folder.
prakash#prakash-Lenovo-ideapad-100-15IBY:~/projects/MasterQuote$ pip3 install mysqlclient
Output :
Collecting mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.3.12
DATABASE SETTINGS :
DATABASES = {
'default' :{
'ENGINE' : 'django.db.backends.mysql',
'NAME' :'MasterQuote',
'USER' : 'root',
'PASSWORD' : 'root',
'HOST' : 'localhost',
'PORT' : ''
}
}
But i try to migrate this error occured
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/home/prakash/.local/lib/python3.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/usr/local/lib/python3.6/dist-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.6/dist-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/usr/local/lib/python3.6/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 114, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/usr/local/lib/python3.6/dist-packages/django/db/models/base.py", line 315, in add_to_class
value.contribute_to_class(cls, name)
File "/usr/local/lib/python3.6/dist-packages/django/db/models/options.py", line 205, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/usr/local/lib/python3.6/dist-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 202, in __getitem__
backend = load_backend(db['ENGINE'])
File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.6/dist-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
First activate the virtual environment and then do,
pip install mysqlclient

Categories

Resources