我遇到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.不确定这是否相关。
答案 0 :(得分:1)
max_length
的 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崩溃。
我认为您可以更改权限名称。