allposts_vitali
@allposts_vitali

При использовании тестов на Django заканчивается ошибкой, как исправить?

Здравствуйте, решил написать небольшой тест для приложения. Ввел стандартную команду
python manage.py test myapp
, выдал БД разрешения на создание таблиц ALTER USER admin_twitter CREATEDB;, запустил и получил ошибку, в чем может быть проблема?

python manage.py test myapp
Creating test database for alias 'default'...
Got an error creating the test database: database "test_twitter" already exists

Type 'yes' if you would like to try deleting the test database 'test_twitter', 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/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vitali/DjangoProjects/twitter/env/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/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
    super(Command, self).execute(*args, **options)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/vitali/DjangoProjects/twitter/env/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/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/test/runner.py", line 147, in run_tests
    old_config = self.setup_databases()
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/test/runner.py", line 109, in setup_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/test/runner.py", line 299, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 377, in create_test_db
    test_flush=True,
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
    return klass.execute(*args, **defaults)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
    output = self.handle(*args, **options)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 68, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 102, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 108, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 139, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 470, in alter_field
    self._alter_field(model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 550, in _alter_field
    new_default = self.effective_default(new_field)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/backends/schema.py", line 196, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 627, in get_db_prep_save
    prepared=False)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1974, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1969, in get_prep_value
    return self.to_python(value)
  File "/home/vitali/DjangoProjects/twitter/env/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1956, in to_python
    params={'value': value},
django.core.exceptions.ValidationError: [u"\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 '0.0.0' \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442. \u041e\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 HH:MM[:ss[.uuuuuu]]."]
  • Вопрос задан
  • 1426 просмотров
Пригласить эксперта
Ответы на вопрос 3
mukizu
@mukizu
Попробуйте почистить миграции и снова прогнать python manage.py migrate перед тестами
Ответ написан
un1t
@un1t
Попробуй такие настройки для тестов

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': ':memory:',
    }
}
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы