Задать вопрос
maximkv25
@maximkv25
web-developer

Как исправить ошибку при запуске тестов?

Приветствую, как исправить ошибку чтоб удалить тестовую бд?

Creating test database for alias 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_develop'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_develop', or 'no' to cancel: yes
Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/commands/test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/commands/test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/test/runner.py", line 532, in run_tests
    old_config = self.setup_databases()
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/test/runner.py", line 482, in setup_databases
    self.parallel, **kwargs
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/test/runner.py", line 726, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
    run_syncdb=True,
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/__init__.py", line 119, in call_command
    return command.execute(*args, **defaults)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
    field,
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/backends/mysql/schema.py", line 50, in add_field
    super(DatabaseSchemaEditor, self).add_field(model, field)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 382, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 145, in column_sql
    default_value = self.effective_default(field)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 210, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 728, in get_db_prep_save
    prepared=False)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1461, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1440, in get_prep_value
    value = super(DateTimeField, self).get_prep_value(value)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1296, in get_prep_value
    return self.to_python(value)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 1399, in to_python
    parsed = parse_datetime(value)
  File "/home/maxim/PycharmProjects/venv/alpha/lib/python3.5/site-packages/django/utils/dateparse.py", line 93, in parse_datetime
    match = datetime_re.match(value)
TypeError: expected string or bytes-like object
  • Вопрос задан
  • 359 просмотров
Подписаться 1 Оценить Комментировать
Решения вопроса 1
Мне кажется, что проблема возникает не при удалении базы, а при создании новой, при применении миграций для какого-то из полей DateTimeField.

  • Если проект учебный и миграции удалить не жалко - то удалите и сделайте новые, проверьте, будет ли проблема повторяться.
  • Если жалко - сделайте grep DateTimeField */migrations/* по всем миграциям и посмотрите, нет ли там где-нибудь неправильных значений datetime (например, в качестве аргумента default).
  • И также проверьте те же поля во всех models.py на предмет того же самого.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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