Django and mysql problems on Mavericks - python

I'm running Mac OSX 10.9 Mavericks. I'm trying to run django under python 3. Because I'm running Python 3 I have to get the official connector from the mysql devs here gave it a quick test in the shell and it works.
I ran python manage.py runserver with "mysql.connector.django" as the engine having seen an example here and I got this error:
django.core.exceptions.ImproperlyConfigured: 'mysql.connector.django' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'mysql', u'oracle', u'postgresql_psycopg2', u'sqlite3'
Error was: No module named mysql.connector.django.base
So I switch back to the default using "django.db.backends.mysql" as my engine and I get this error:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have no idea how to proceed. I can't install MySQLdb because I'm running my django install under python3 and it's unsupported, but I'm definitely missing something with this connector.

For python 2.7, 3.3+ there is a driver called mysqlclient that works with django 1.8
pip install mysqlclient
And in your settings
DATABASES = {
'default': {
'NAME': '',
'ENGINE': 'django.db.backends.mysql',
'USER': '',
'PASSWORD': '',
}
}
Here's the official django documentation about the mysql drivers:
https://docs.djangoproject.com/en/1.8/ref/databases/#mysql-db-api-drivers

Related

Django Segmentation fault when changing database to mysql in settings.py

My question is similar to the one at error connecting mysql to django which has gone unanswered.
I am using python 3.6.5, mysql server-5.7.29 and Ubuntu 18.04 LTS. I am trying to setup mysql for my django application but I am receiving Segmentation fault.
(env) monu#monu:~/Desktop/ShubhamProject/ShubhamProject$ python manage.py runserver
Segmentation fault (core dumped)
If I use the default sqlite3 database, server comes up.
Database section in settings.py looks like
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'sports_website',
'USER': 'nonroot',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
}
}
Using the following packages
asgiref==3.2.3
Django==3.0.3
django-crispy-forms==1.8.1
mysqlclient==1.4.6
pytz==2019.3
sqlparse==0.3.0
install pymysql and add below in settings.py on top.
import pymysql
pymysql.version_info = (1, 4, 6, 'final', 0)
pymysql.install_as_MySQLdb()
this is because django use MySQLdb driveļ¼Œbut MYSQLdb not support python3, so set the drive is pymysql in settings.py:
first :pip install pymysql
and add: import pymysql
pymysql.install_as_MySQLdb()

How to connect django with mongodb compass?

I installed djongo through pip. My django version is 3 although I checked version 2 also to make it work. Python version is 3. I also made change in settings.py but whenever I load the command with makemigrations, it gives me following error.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql','oracle','postgresql','sqlite3'
I don't know what to do with this now?
settings.py
DATABASES = {
default: {
'ENGINE': 'djongo',
'NAME' : 'django_db'
}
}
there's this awesome package that allows you to connect Django with MongoDB it's called mongoengine
http://mongoengine.org/
here's also a link for their documentation
http://docs.mongoengine.org/

Python django error

am new to python and django
I am trying to build a small python django application on my local windows laptop.
i am not able to underlying tables required for my Django project as when i run "python manage.py syncdb" i get the below error
` Error :django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python? '
And when i try running "pip install mysqlclient" i get the below error
'error: Microsoft Visual C++ 10.0 is required. Get it with "Microsoft Windows SDK 7.1": www.microsoft.com/download/details.aspx?id=8279'
I am stuck in this step and not able to find any leads. can someone suggest any workaround
By default Django is configured to use Sqlite database. See settings.py file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
You have it configured to use MySQL database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DATABASE_NAME',
'USER': 'DB_USERNAME',
'PASSWORD': 'DB_PASSWORD',
'HOST': '127.0.0.1',
'PORT': '3306'
}
}
If it's a small test project, I would recommend you to switch back to Sqlite, but if you intend to run your project later in production using MySQL, then better use MySQL in development process.
Install:
MySQL or MariaDB locally on your computer
Windows SDK from www.microsoft.com/download/details.aspx?id=8279
run pip install mysqlclient - now it should succeed

ValueError when db settings altered in settings.py Django documentation

Hi iam following Django documenatation,I have installed Django 1.8 and python 2.7.12,I want to connect to oracle 11g database,For this I have altered settings.py file in mysite folder like this for DATABASE information
DATABASES = {
'default': {
'ENGINE' : 'django.db.backends.oracle',
'NAME' : 'XE',
'USER' : 'chandan',
'PASSWORD' : 'root',
'HOST' : 'localhost', }
}
Iam getting below error when i run python manage.py runserver and
python manage.py migrate
from .utils import InsertIdVar, Oracle_datetime, convert_unicode
File "C:\PYTHON27\lib\site-packages\django\db\backends\oracle\utils.py", line 10, in <module>
(int(Database.version.split('.', 2)[1]) >= 1 or
ValueError: invalid literal for int() with base 10: '0rc1'
Do i have to alter my DATABASE part in settings.py or what needs to be done?
Firstly, check your connection for ORACLE.
Add port information.
Be sure to install cx_Oracle driver-lastest version.
You are running an incompatible oracle version, Django's oracle drivers tries to cast the version string as an int, which obviously fails as the oracle version string contains 0rc1.
You might want to install a newer release of Django, 1.8 is EOL and does not receive any security patches. And if you are starting a new project, do yourself a favor and choose Python 3 :-)

Django MySql-Connector-Python - unknown error [duplicate]

OS : CentOS 6.4
python version 3.4
django version 1.8
I had studies about django framework. Then, I going to move to storage part. At first of study, the default database is sqlite. So I was change some values in the settings.py file.
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
#}
DATABASES = {
'default' : {
'ENGINE' : 'mysql.connector.django',
'NAME' : 'dj_mysql',
'USER' : 'root',
'PASSWORD' : '',
'HOST' : '127.0.0.1',
'PORT' :''
}
}
I typed "python3 manage.my migrate", and I got these errors.
How can I overcome this situation. TT;
I'm struggling all day long.
It looks like you're trying to use MySQL connector. The Django docs suggest that it doesn't always support the latest version of Django. This bug report suggests that 2.1.3 supports Django 1.8, but users were still reporting problems with 2.1.3 on that bug report and in this question.
The Django docs recommend that you use mysqlclient to access MySQL databases with Django.
It's easy to install, for example with pip:
pip install mysqlclient
Then all you need to do is change your databases setting to
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.mysql',
...
You should update the mysql-connector-python, since the old version don't support Django 1.8 well.
As the documentation of Django goes:
MySQL Connector/Python is available from the download page. The Django >adapter is available in versions 1.1.X and later. It may not support the >most recent releases of Django.
Use the following command to update it from the MySQL website:
pip install http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz

Categories