简体   繁体   中英

Django 1.6.5 test failing before executing tests

I am having an issue with Django 1.6.5 tests failing before it even starts to execute.

If I run python manage.py test it fails with the below message:

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'

So far I've been unable to figure out what is causing this and how to solve it. I know that our database can only support index's of 191 chars or less, not sure if this is something to do with it.

Edit I am using UTF8MB4 encoding on the database (to support Emoji's etc...). This means my unique fields are limited to 191 and not 255. Not sure if this could be related.

max_length of django Permission.name is 50:

https://github.com/django/django/blob/1.6c1/django/contrib/auth/models.py#L71

And you have permission with name 'Can delete event participant check in location stats user' which length is 57. Thats why django crashes.

I think you can change name of your permissions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM