I've just installed Python 3.3.0, mysql-connector and Django. Then I created my first application called mysite. In settings.py I added these lines:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'mydb',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
'PORT': '3306',
}
}
When I run the server and enter the admin page 127.0.0.1:8000/admin/, I see a long list of errors starting with AttributeError at /admin/ 'DatabaseWrapper' object has no attribute 'Database'. I do not know what to do with all this stuff. The full error description is:
AttributeError at /admin/
'DatabaseWrapper' object has no attribute 'Database'
Request Method: POST
Request URL: http://localhost:8000/admin/
Django Version: 1.6.1
Exception Type: AttributeError
Exception Value:
'DatabaseWrapper' object has no attribute 'Database'
Exception Location: C:\Python33\lib\site-packages\django\db\utils.py in __exit__, line 86
Python Executable: C:\Python33\python.exe
Python Version: 3.3.0
Python Path:
['C:\\mysite',
'C:\\Windows\\system32\\python33.zip',
'C:\\Python33\\DLLs',
'C:\\Python33\\lib',
'C:\\Python33',
'C:\\Python33\\lib\\site-packages']
EDIT
When I run python manage.py syncdb, I also get a long list of errors:
C:\mysite>python manage.py syncdb
Creating tables ...
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
399, in execute_from_command_line
utility.execute()
File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line
392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 242,
in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 285,
in execute
output = self.handle(*args, **options)
File "C:\Python33\lib\site-packages\django\core\management\base.py", line 415,
in handle
return self.handle_noargs(**options)
File "C:\Python33\lib\site-packages\django\core\management\commands\syncdb.py"
, line 96, in handle_noargs
sql, references = connection.creation.sql_create_model(model, self.style, se
en_models)
File "C:\Python33\lib\site-packages\django\db\backends\creation.py", line 83,
in sql_create_model
model, f, known_models, style)
TypeError: sql_for_inline_foreign_key_references() takes 4 positional arguments
but 5 were given
解决方案
Ok, so I was experiencing exactly the same problem. There are lots of suggestions on how you can modify part of existing libraries to make Python3 work with MySQL, but I didn't find any of them to work 100%. I wasn't able to make official MySQL Python connector to work with Django and Python 3.3.
What did work was switching to PyMySQL library instead. Few months back I already tried it but it didn't work for me back then. Now, there is a new version, 0.6.1 which worked out of the box. So, few more details:
My environment: OSX 10.9 , Python 3.3.3, Django 1.6.1, MyPySQL 0.6.1, MySQL Server 5.5 on Windows
How to make it work:
Install PyMySQL version 0.6.1 (https://github.com/PyMySQL/PyMySQL/): you can install it either by using pip, i.e. : pip install PyMySQL or by manually downloading the package; there is a good documentation on their website on how to do that.
Open your Django App __init__.py and paste the following lines:
import pymysql
pymysql.install_as_MySQLdb()
Now, open settings.py and make sure your DATABASE property looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydb',
'USER': 'dbuser',
'PASSWORD': 'dbpassword',
'HOST': 'dbhost',
'PORT': '3306'
}
}
That's it, you should be able to execute python manage.py syncdb so init your MySQL DB; see the sample output below:
Creating tables ...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group_permissions
...
...
Creating table socialaccount_socialtoken
You just installed Django's auth system, which means you don't have any superusers defined.
...