Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.7 django.db.utils.OperationalError: no such table: auth_customuser

Tags:

django

testing

Having a load of grief migrating a large 1.6 project to 1.7 with the new migrations. I can now recreate the database using makemigrations and migrate, but when I try to run a test I'm getting this error about auth_customuser. I am using a custom user but it's in my web app and it's not called customuser.

Here's the output from running the tests, with some print statements to try and find out what is going on:

(gmd)iMacs-iMac:gmdz phoebebr$ python manage.py test web -v 3

Creating test database for alias 'default' (':gmd_test_db:')...
Destroying old test database 'default'...
Type 'yes' if you would like to try deleting the test database ':gmd_test_db:', or 'no' to cancel: yes
starting results iter loop
Operations to perform:
  Synchronize unmigrated apps: json_field, ipn, registration
  Apply all migrations: web, sessions, admin, sites, auth, tastypie, contenttypes, taggit
Synchronizing apps without migrations:
Running pre-migrate handlers for application auth
Running pre-migrate handlers for application contenttypes
Running pre-migrate handlers for application sessions
Running pre-migrate handlers for application sites
Running pre-migrate handlers for application admin
Running pre-migrate handlers for application taggit
Running pre-migrate handlers for application web
Running pre-migrate handlers for application json_field
Running pre-migrate handlers for application registration
Running pre-migrate handlers for application tastypie
Running pre-migrate handlers for application ipn
  Creating tables...
    Creating table registration_registrationprofile
    Creating table paypal_ipn
  Installing custom SQL...
  Installing indexes...
    Installing index for ipn.PayPalIPN model
Loading 'initial_data' fixtures...
Checking '/Users/phoebebr/Development/gmdz/web/fixtures' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz/web/fixtures'.
Checking '/Users/phoebebr/Development/gmdz' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz'.
Loading 'initial_data' fixtures...
Checking '/Users/phoebebr/Development/gmdz/web/fixtures' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz/web/fixtures'.
Checking '/Users/phoebebr/Development/gmdz' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz'.
Loading 'initial_data' fixtures...
Checking '/Users/phoebebr/Development/gmdz/web/fixtures' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz/web/fixtures'.
Checking '/Users/phoebebr/Development/gmdz' for fixtures...
No fixture 'initial_data' in '/Users/phoebebr/Development/gmdz'.
Installed 0 object(s) from 0 fixture(s)
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying web.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying sites.0001_initial... OK
  Applying taggit.0001_initial... OK
  Applying tastypie.0001_initial... OK
Running post-migrate handlers for application auth

...

Running post-migrate handlers for application json_field
starting results iter loop
Running post-migrate handlers for application registration
starting results iter loop
starting results iter loop
Adding permission 'registration | registration profile | Can add registration profile'
Adding permission 'registration | registration profile | Can change registration profile'
Adding permission 'registration | registration profile | Can delete registration profile'
starting results iter loop
(28, u'registration profile', u'registration', u'registrationprofile')
done
Running post-migrate handlers for application tastypie
starting results iter loop
starting results iter loop
starting results iter loop
Adding permission 'tastypie | api access | Can add api access'
Adding permission 'tastypie | api access | Can change api access'
Adding permission 'tastypie | api access | Can delete api access'
Adding permission 'tastypie | api key | Can add api key'
Adding permission 'tastypie | api key | Can change api key'
Adding permission 'tastypie | api key | Can delete api key'
starting results iter loop
(29, u'api access', u'tastypie', u'apiaccess')
done
(30, u'api key', u'tastypie', u'apikey')
done
Running post-migrate handlers for application ipn
starting results iter loop
starting results iter loop
Adding permission 'ipn | PayPal IPN | Can add PayPal IPN'
Adding permission 'ipn | PayPal IPN | Can change PayPal IPN'
Adding permission 'ipn | PayPal IPN | Can delete PayPal IPN'
starting results iter loop
(31, u'PayPal IPN', u'ipn', u'paypalipn')
done
starting results iter loop
(u'contenttypes', u'0001_initial')
done
(u'auth', u'0001_initial')
done
(u'web', u'0001_initial')
done
(u'admin', u'0001_initial')
done
(u'sessions', u'0001_initial')
done
(u'sites', u'0001_initial')
done
(u'taggit', u'0001_initial')
done
(u'tastypie', u'0001_initial')
done
starting results iter loop

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/creation.py", line 385, in create_test_db
    self.connection._test_serialized_contents = self.serialize_db_to_string()
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/creation.py", line 421, in serialize_db_to_string
    serializers.serialize("json", get_objects(), indent=None, stream=out)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/serializers/__init__.py", line 128, in serialize
    s.serialize(queryset, **options)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/core/serializers/base.py", line 52, in serialize
    for obj in queryset:
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/creation.py", line 417, in get_objects
    for obj in queryset.iterator():
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/models/query.py", line 265, in iterator
    for row in compiler.results_iter():
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 701, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 788, in execute_sql
    cursor.execute(sql, params)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/phoebebr/Development/venvs/gmd/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: auth_customuser

What is looking for auth_customuser?

Looking in the code directory

$ grep -r "customuser" *
Binary file :gmd_test_db: matches

Looking in the virtualenv

(gmd)$ grep -r "customuser" *
lib/python2.7/site-packages/django/contrib/auth/fixtures/custom_user.json:        "model": "auth.customuser",
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        # Add permissions auth.add_customuser and auth.change_customuser
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        perms = models.Permission.objects.filter(codename__in=('add_customuser', 'change_customuser'))
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        @permission_required(['auth.add_customuser', 'auth.change_customuser'])
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        @permission_required('auth.add_customuser')
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        @permission_required(['auth.add_customuser', 'auth.change_customuser', 'non-existent-permission'])
lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.py:        @permission_required(['auth.add_customuser', 'auth.change_customuser', 'non-existent-permission'], raise_exception=True)
Binary file lib/python2.7/site-packages/django/contrib/auth/tests/test_decorators.pyc matches

So put some traces into the require_permission decorator but it is never triggered, as I would expect it being in the test suite.

So I've run out of ideas now. It must be my problem as nobody else has reported this error, I just can't think where to look...

Requirements:

Django==1.7.1
MySQL-python==1.2.5
Pillow==2.6.1
South==1.0.1
Unidecode==0.04.16
argparse==1.2.1
django-crontab==0.6.0
django-facebook==6.0.2
django-google-maps==0.2.3
django-nose==1.3
django-paypal==0.1.5
django-taggit==0.12.2
django-tastypie==0.12.1
jsonfield==1.0.0
mock==1.0.1
nose==1.3.4
python-dateutil==2.3
python-mimeparse==0.1.4
pytz==2014.10
qrcode==5.1
requests==2.5.0
six==1.8.0
wsgiref==0.1.2

Also have the following apps in the project as they have minor tweeks

lazysignup
django-registration
like image 667
PhoebeB Avatar asked Dec 11 '14 22:12

PhoebeB


1 Answers

I think the answer is here:

https://code.djangoproject.com/ticket/19495

It looks like you have an app of your own in the project called auth and this is conflicting with django.contrib.auth As mentioned in the ticket above, the last segment of the app path, i.e. auth has to be unique across all apps (including Django's own) used in your project.

So what happens when you run the the tests is Django finds the fixture django/contrib/auth/fixtures/custom_user.json (which comes with Django). But it gets confused and tries to load it against your auth app's models instead of the django.contrib.auth models.

You should rename your auth app to something unique.

like image 109
Anentropic Avatar answered Sep 19 '22 14:09

Anentropic