4

我将我的 django 应用程序迁移到 Django 1.5。我进行了配置AUTH_USER_MODEL,一切看起来都很好,但是当我尝试创建一些测试时,出现以下错误:

DatabaseError: (1146, "Table 'test_X.auth_user' doesn't exist")

测试.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)

设置.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)

我怎样才能使我的测试正常工作?

4

1 回答 1

4

您必须在 myuser/models.py 上创建自定义用户

就像https://docs.djangoproject.com/en/dev/topics/auth/customizing/#a-full-example

于 2013-04-15T03:40:08.993 回答