Django 1.6.5 测试在执行测试之前失败
Django 1.6.5 test failing before executing tests
我遇到 Django 1.6.5 测试在开始执行之前就失败的问题。
如果我 运行 python manage.py test
它失败并显示以下消息:
Creating test database for alias 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_marks_project'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_marks_project', or 'no' to cancel: yes
Destroying old test database 'default'...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mark/.virtualenvs/marks_project/local/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 "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 145, in run_tests
old_config = self.setup_databases()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 107, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 279, in setup_databases
verbosity, autoclobber=not interactive)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 339, in create_test_db
load_initial_data=False)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 101, in create_permissions
auth_app.Permission.objects.using(db).bulk_create(perms)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 359, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 838, in _batched_insert
using=self.db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 903, in execute_sql
cursor.execute(sql, params)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 207, in execute
if not self._defer_warnings: self._warning_check()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 117, in _warning_check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Data truncated for column 'name' at row 356
Warning: local() encountered an error (return code 1) while executing 'python manage.py test'
到目前为止,我一直无法弄清楚是什么原因造成的以及如何解决它。我知道我们的数据库只能支持 191 个字符或更少的索引,不确定是否与它有关。
编辑
我在数据库上使用 UTF8MB4
编码(以支持表情符号等...)。这意味着我的唯一字段限制为 191 而不是 255。不确定这是否相关。
max_length
的 django Permission.name
是 50:
https://github.com/django/django/blob/1.6c1/django/contrib/auth/models.py#L71
并且您拥有名称 'Can delete event participant check in location stats user'
的权限,长度为 57。这就是 django 崩溃的原因。
我想你可以更改权限的名称。
我遇到 Django 1.6.5 测试在开始执行之前就失败的问题。
如果我 运行 python manage.py test
它失败并显示以下消息:
Creating test database for alias 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_marks_project'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_marks_project', or 'no' to cancel: yes
Destroying old test database 'default'...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mark/.virtualenvs/marks_project/local/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 "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/south/management/commands/test.py", line 8, in handle
super(Command, self).handle(*args, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 145, in run_tests
old_config = self.setup_databases()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 107, in setup_databases
return setup_databases(self.verbosity, self.interactive, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/test/runner.py", line 279, in setup_databases
verbosity, autoclobber=not interactive)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 339, in create_test_db
load_initial_data=False)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 415, in handle
return self.handle_noargs(**options)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 112, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/core/management/sql.py", line 216, in emit_post_sync_signal
interactive=interactive, db=db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py", line 101, in create_permissions
auth_app.Permission.objects.using(db).bulk_create(perms)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 359, in bulk_create
self._batched_insert(objs_without_pk, fields, batch_size)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 838, in _batched_insert
using=self.db)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/query.py", line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 903, in execute_sql
cursor.execute(sql, params)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 207, in execute
if not self._defer_warnings: self._warning_check()
File "/home/mark/.virtualenvs/marks_project/local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 117, in _warning_check
warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Data truncated for column 'name' at row 356
Warning: local() encountered an error (return code 1) while executing 'python manage.py test'
到目前为止,我一直无法弄清楚是什么原因造成的以及如何解决它。我知道我们的数据库只能支持 191 个字符或更少的索引,不确定是否与它有关。
编辑
我在数据库上使用 UTF8MB4
编码(以支持表情符号等...)。这意味着我的唯一字段限制为 191 而不是 255。不确定这是否相关。
max_length
的 django Permission.name
是 50:
https://github.com/django/django/blob/1.6c1/django/contrib/auth/models.py#L71
并且您拥有名称 'Can delete event participant check in location stats user'
的权限,长度为 57。这就是 django 崩溃的原因。
我想你可以更改权限的名称。