2

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 <module>
 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
4
  • have you tried running python manage.py syncdb? if so did you go through the process of making the superuser? Commented Jan 3, 2014 at 16:23
  • Also, you should have some commandline tool installed, like CygWin. Commented Jan 3, 2014 at 16:24
  • Please, have a look at my post again. I added the list of errors that I got after running python manage.py syncdb Commented Jan 3, 2014 at 16:43
  • See stackoverflow.com/questions/21251682/… for a solution. It's a fairly straightforward fix. Commented Jan 25, 2014 at 22:31

2 Answers 2

1

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:

  1. 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.

  2. Open your Django App __init__.py and paste the following lines:

    import pymysql
    pymysql.install_as_MySQLdb() 
    
  3. 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'
        }
    }
    
  4. 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.
    ...
    
Sign up to request clarification or add additional context in comments.

Comments

0

I had same error for Django 1.8.9, Python 3.6.12. And I was using django-transaction-hooks==0.2. And my DATABASES settings were

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    .
    .

I fixed the issue by using DATABASES settings as follows

DATABASES = {
'default': {
    'ENGINE': 'transaction_hooks.backends.mysql',
    .
    .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.