我将我的Django应用程序迁移到了Django 1.5。我配置了AUTH_USER_MODEL
,一切看起来都很好,但是当我尝试创建一些测试时,我遇到了以下错误:
DatabaseError: (1146, "Table 'test_X.auth_user' doesn't exist")
tests.py
class XXTest(unittest.TestCase):
def setUp(self):
self.data= {
'password1':'aaaaa',
'password2':'aaaaa',
'city':'NY', (....)
}
self.client = Client()
def test_register(self):
c = Client()
resp = self.client.post('/register/user/', self.data)
self.assertEqual(resp.status_code, 200)
Settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
...
'myuser',
)
AUTH_USER_MODEL = 'myuser.MyUser'
我正在使用MySQL,实际上表myuser没有在测试数据库中创建。
如果我运行python manage.py migrate
,我不会收到任何错误。但是如果我运行:
python manage.py syncdb
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.sites
> django.contrib.messages
> django.contrib.staticfiles
> django.contrib.admin
> django.contrib.flatpages
> django.contrib.sitemaps
未同步(使用迁移):
- myuser
(use ./manage.py migrate to migrate these)
我该如何使我的测试正常工作?