I need connect my Django website to Azure SQL database.I use visual studio. And Python 2.7 for 64 bit.
I use this https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-ptvs-django-sql/ for create database config
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'xxx',
'USER': 'xxx',
'PASSWORD': 'xxx',
'HOST': 'xxx.database.windows.net',
'PORT': '1433',
'OPTIONS': {
'driver': 'SQL Server Native Client 11.0',
'MARS_Connection': 'True',
}
}
}
I installed pips: pyodbc and django-pyodbc-azure - I think that them for 32 bit.
If I run python manage.py syncdb from console - > error:
django.core.exceptions.improperlyconfigured 'sql_server.pyodbc' isn't an available databace backend.
No module named sql_server.pyodbc.base
If I run python-> Django Sync db from visual studio -> error:
Unknown command: 'syncdb'
Type 'manage.py help' for usage.
The Python REPL process has exited
I installed the latest python 2.7 64 bits version from https://www.python.org/ftp/python/2.7.11/python-2.7.11.amd64.msi , and leveraged it to create a virtual env in Visual Studio, install modules from requirements.txt
, configured database info the same as you.
Then clicked sync db
, but I did occur your issue, it worked fine on my side.
You can try to leverage virtual env as the step 3 and step 4 mention on the post https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-ptvs-django-sql/#create-the-project .
And here are the python modules with version in used: Django==1.8.4 pyodbc==3.0.10 django-pyodbc-azure==1.8.3.0
确保sql_server在Python_xx \\ Lib \\ site-packages \\下或环境PATH或PYTHONPATH中
Yes, you can, but if your Python is x86_64 version, then your packages pyodbc and django-pyodbc-azure need to be build for this 64 bits version, check this first if you install the packages from VS or directly from shell/powershell. Check your $PYTHONPATH
I assume that you are using Django 1.9, syncdb was deprecated from Django 1.7 and don't work with Django 1.9, change your syncdb
commands with ./manage.py makemigrations
and ./manage.py migrate
check:
https://docs.djangoproject.com/en/1.9/intro/tutorial02/
https://docs.djangoproject.com/en/1.9/topics/migrations/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.