0

I'm developing a large Django project and I'm beginning to write some tests. But I ran into a problem when running them. When I run python manage.py test I get the following error:

$ project/ python manage.py test
                    project/env/lib/python3.7/site-packages/django/db/models/base.py:319: RuntimeWarning: Model 'accounts.manager' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)
Creating test database for alias 'default'...
Got an error creating the test database: (1007, "Can't create database 'test_partyadvisor'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_partyadvisor', or 'no' to cancel: yes
Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "project/env/lib/python3.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "project/env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 101, in execute
    return self.cursor.execute(query, args)
  File "project/env/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "project/env/lib/python3.7/site-packages/MySQLdb/cursors.py", line 312, in _query
    db.query(q)
  File "project/env/lib/python3.7/site-packages/MySQLdb/connections.py", line 224, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1170, "BLOB/TEXT column 'content' used in key specification without a key length")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "project/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "project/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "project/env/lib/python3.7/site-packages/django/core/management/commands/test.py", line 29, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "project/env/lib/python3.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "project/env/lib/python3.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "project/env/lib/python3.7/site-packages/django/core/management/commands/test.py", line 62, in handle
    failures = test_runner.run_tests(test_labels)
  File "project/env/lib/python3.7/site-packages/django/test/runner.py", line 601, in run_tests
    old_config = self.setup_databases()
  File "project/env/lib/python3.7/site-packages/django/test/runner.py", line 546, in setup_databases
    self.parallel, **kwargs
  File "project/env/lib/python3.7/site-packages/django/test/utils.py", line 187, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "project/env/lib/python3.7/site-packages/django/db/backends/base/creation.py", line 69, in create_test_db
    run_syncdb=True,
  File "project/env/lib/python3.7/site-packages/django/core/management/__init__.py", line 131, in call_command
    return command.execute(*args, **defaults)
  File "project/env/lib/python3.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "project/env/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "project/env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "project/env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "project/env/lib/python3.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "project/env/lib/python3.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "project/env/lib/python3.7/site-packages/django/db/migrations/operations/models.py", line 97, in database_forwards
    schema_editor.create_model(model)
  File "project/env/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 319, in create_model
    self.execute(sql, params or None)
  File "project/env/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 136, in execute
    cursor.execute(sql, params)
  File "project/env/lib/python3.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "project/env/lib/python3.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "project/env/lib/python3.7/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "project/env/lib/python3.7/site-packages/django/db/backends/utils.py", line 62, in execute
    return self.cursor.execute(sql)
  File "project/env/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 101, in execute
    return self.cursor.execute(query, args)
  File "project/env/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "project/env/lib/python3.7/site-packages/MySQLdb/cursors.py", line 312, in _query
    db.query(q)
  File "project/env/lib/python3.7/site-packages/MySQLdb/connections.py", line 224, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'content' used in key specification without a key length")

The test database is created, but for some reason I can not use it (?). My database configuration is, (in the settings.py file):

DATABASES = {
        "default": {
            "ENGINE": "django.db.backends.mysql",
            "HOST": env.get("database").get("HOST"),
            "PORT": env.get("database").get("PORT"),
            "NAME": env.get("database").get("NAME"),
            "USER": env.get("database").get("USER"),
            "PASSWORD": env.get("database").get("PASS")
        }
}

Notes:

  1. The user I use to access the db has all grants on it.
  2. I tried to run the tests using the root user, and got the same error.
  3. The normal db and the cache one work perfectly.
  4. Also ran makemigrations and migrate.
  5. Deleted the test db from MySQL shell and re-run python manage.py test, got the same error.
  6. Option --keep-db not working either.

System is Ubuntu 18.04 and I'm using Django 1.11 and MySQL 5.7.

2pac
  • 73
  • 2
  • 6
  • you have created your models in model.py ? – Farhani Walid Oct 28 '19 at 19:33
  • @FarhaniWalid yes, as I said the normal env is working fine – 2pac Oct 28 '19 at 22:59
  • [interlinguex](https://stackoverflow.com/users/13077826) wrote an [Answer](https://stackoverflow.com/a/66278890) saying "A rather detailed comment concerning this error message, `1170, "BLOB/TEXT column 'content' used in key specification without a key length"` , has been posted on stackexchange (see [MySQL error: key specification without a key length](https://stackoverflow.com/questions/1827063/mysql-error-key-specification-without-a-key-length)) Would that help solve the issue in your case?" – Scratte Feb 20 '21 at 10:11

0 Answers0