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

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

Related

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/

Creating SuperUser on a custom database (not default)

I am currently working on a multi-tenant django application. Since the requirement of multi-tenancy, for starters, I have created a second database. However, I am unable to create a SuperUser in the newly created database.
I did try the answer listed Django fails to create superuser in other db than 'default'
However, no luck.
Getting the following output on compile:
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly co
nfigured. Please supply the ENGINE value. Check settings documentation for more
details.
Settings.py
DATABASES = {
'default': {},
'Alora': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'Alora',
'USER': 'postgres',
'PASSWORD': 'somepassword',
}
}
Python Version
C:\Users\User>python --version
Python 3.6.3
Django Version
C:\Users\User>django-admin --version
2.2
Tried python manage.py createsuperuser --database=Alora.
Received the error stated above.
Any help is deeply appreciated.
Thanks!

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

Can i use sqlserver in django 1.6 and python3

I have installed django-sqlserver (0.5) with pip. In the docs says that engine must be sqlserver_ado but it does not work, this is the output Error was: No module named sqlserver_ado
This is my settings file:
options = {'use_mars': True,
'allow_nulls_in_unique_constraints': False, # sqlserver doesn't fully support multiple nulls in unique constraint
'extra_params': 'DataTypeCompatibility=80;MARS Connection=True;',
'use_legacy_date_fields': False,
}
DATABASES = {
'default': {
'ENGINE': 'sqlserver_ado',
'HOST': 'ip',
'NAME': 'db',
'USER': 'user',
'PASSWORD': 'password',
'OPTIONS': options,
}
}
You need django-mssql which is imported using import sqlserver_ado
The relevant info from the django-mssql docs:
Although the project is named django-mssql the python module is named sqlserver_ado
Python
This backend requires Python 2.6 or newer. Python 3.x support will be investigated when Django supports it.
The django packages page shows no support for python 3

Django and mysql problems on Mavericks

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

Categories