堆栈跟踪:
Creating test database for alias 'default'...
Destroying old test database 'default'...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Py27_64\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Py27_64\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Py27_64\lib\site-packages\django\core\management\commands\test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "C:\Py27_64\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Py27_64\lib\site-packages\django\core\management\commands\test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "C:\Py27_64\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Py27_64\lib\site-packages\django\core\management\commands\test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "C:\Py27_64\lib\site-packages\django\test\runner.py", line 145, in run_tests
old_config = self.setup_databases()
File "C:\Py27_64\lib\site-packages\django\test\runner.py", line 107, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "C:\Py27_64\lib\site-packages\django\test\runner.py", line 279, in setup_databases
verbosity, autoclobber=not interactive)
File "C:\Py27_64\lib\site-packages\django\db\backends\creation.py", line 339, in create_test_db
load_initial_data=False)
File "C:\Py27_64\lib\site-packages\django\core\management\__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "C:\Py27_64\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Py27_64\lib\site-packages\django\core\management\base.py", line 415, in handle
return self.handle_noargs(**options)
File "C:\Py27_64\lib\site-packages\django\core\management\commands\syncdb.py", line 107, in handle_noargs
cursor.execute(statement)
File "C:\Py27_64\lib\site-packages\django\db\backends\util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "C:\Py27_64\lib\site-packages\django\db\utils.py", line 99, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Py27_64\lib\site-packages\django\db\backends\util.py", line 51, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" already exists
我的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',
'myApp',
)
我的怀疑:在models.py中我手动添加了类AuthUser(),原因是之前对models.py的实际工作方式存在误解。
我想要自定义字段/属性,所以我认为这是实现它的方法。另外,我实际上修改了由Django生成的postgres中的auth_user表来添加自定义字段。
现在,当我尝试运行./manage.py测试myApp时,我得到了上面的堆栈跟踪。下面是类AuthUser():
class AuthUser(models.Model):
password = models.CharField(max_length=128, blank=True)
username = models.CharField(max_length=30, blank=True)
first_name = models.CharField(max_length=30, blank=True)
last_name = models.CharField(max_length=30, blank=True)
is_staff = models.BooleanField(default=True)
is_active = models.BooleanField(default=True)
email = models.CharField(max_length=75, blank=True)
uuid = models.Uuid()
role = models.CharField(max_length=20, blank=True)
curricula = models.ManyToManyField(Curricula,
through='CurriculaUserMap',
null=True,
blank=True)
class Meta:
db_table = 'auth_user'
get_latest_by = 'id'
def __unicode__(self):
return self.username
我还没有验证上面的堆栈跟踪是由于在执行./manage.py test myApp
的上下文中的models.py中定义类AuthUser()而引起的。我的问题是:
./manage.py test myApp
并继续进行单元测试?我担心的是,如果我跳起来解决这个“正确的方式”;它几乎可以打破一切。
谢谢你的时间!答案 0 :(得分:0)
所以我回答了自己的问题: