Django 1.7 django.db.utils.OperationalError:没有这样的表:auth_customuser

时间:2014-12-11 22:00:16

标签: django testing

随着新的迁移,将一个大的1.6项目迁移到1.7。我现在可以使用makemigrations和migrate重新创建数据库,但是当我尝试运行测试时,我收到有关auth_customuser的错误。我使用的是自定义用户,但它位于我的网络应用程序中,并不称为自定义用户。

这是运行测试的输出,有一些打印语句试图找出发生了什么:

(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

是什么在寻找auth_customuser?

查看代码目录

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

看看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

所以在require_permission装饰器中加入一些痕迹,但它永远不会触发,因为我希望它在测试套件中。

所以我现在已经没想完了。它一定是我的问题,因为没有其他人报告过这个错误,我只是想不出去哪看......

要求:

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

在项目中也有以下应用,因为他们有小小的推文

lazysignup
django-registration

1 个答案:

答案 0 :(得分:2)

我认为答案就在这里:

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

看起来您在项目中有一个名为auth的应用程序,这与django.contrib.auth冲突如上面的故障单中所述,应用程序路径的最后一段,即{{ 1}}必须在项目中使用的所有应用程序(包括Django自己的)中都是唯一的。

当你运行测试时会发生什么,Django找到了夹具auth(随Django一起提供)。但它会混淆并尝试将其加载到您的 django/contrib/auth/fixtures/custom_user.json应用的模型而不是auth模型。

您应该将django.contrib.auth应用重命名为独特的内容。