}

Django SOLUTION: TEST_DATABASE_PREFIX TypeError: can only concatenate str (not "NoneType") to str

Created:

The error

When you execute the django unit tests you get the error:

 Traceback (most recent call last):
 File "/opt/.pycharm\_helpers/pycharm/django\_test\_manage.py", line 168, in <module>
 utility.execute()
 File "/opt/.pycharm\_helpers/pycharm/django\_test\_manage.py", line 142, in execute
 \_create\_command().run\_from\_argv(self.argv)
 File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/test.py", line 23, in run\_from\_argv
 super().run\_from\_argv(argv)
 File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run\_from\_argv
 self.execute(*args, **cmd\_options)
 File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
 output = self.handle(*args, **options)
 File "/opt/.pycharm\_helpers/pycharm/django\_test\_manage.py", line 104, in handle
 failures = TestRunner(test\_labels, **options)
 File "/opt/.pycharm\_helpers/pycharm/django\_test\_runner.py", line 255, in run\_tests
 extra\_tests=extra\_tests, **options)
 File "/opt/.pycharm\_helpers/pycharm/django\_test\_runner.py", line 156, in run\_tests
 return super(DjangoTeamcityTestRunner, self).run\_tests(test\_labels, extra\_tests, **kwargs)
 File "/usr/local/lib/python3.7/site-packages/django/test/runner.py", line 684, in run\_tests
 old\_config = self.setup\_databases(aliases=databases)
 File "/usr/local/lib/python3.7/site-packages/django/test/runner.py", line 606, in setup\_databases
 self.parallel, **kwargs
 File "/usr/local/lib/python3.7/site-packages/django/test/utils.py", line 156, in setup\_databases
 test\_databases, mirrored\_aliases = get\_unique\_databases\_and\_mirrors(aliases)
 File "/usr/local/lib/python3.7/site-packages/django/test/utils.py", line 257, in get\_unique\_databases\_and\_mirrors
 default\_sig = connections[DEFAULT\_DB\_ALIAS].creation.test\_db\_signature()
 File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/creation.py", line 295, in test\_db\_signature
 self.\_get\_test\_db\_name(),
 File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/creation.py", line 153, in \_get\_test\_db\_name
 return TEST\_DATABASE\_PREFIX + self.connection.settings\_dict['NAME']
TypeError: can only concatenate str (not "NoneType") to str

Process finished with exit code 1 eval(ez_write_tag([[580,400],'tutorials_technology-medrectangle-3','ezslot_1',114,'0','0'])); Solution ========

You need to specify a sqlite ENGINE when using unit tests. Open the settings.py and add the just after DATABASES section:

import sys
if 'test' in sys.argv or 'test\_coverage' in sys.argv: #Covers regular testing and django-coverage
 DATABASES['default']['ENGINE'] = 'django.db.backends.sqlite3'
 DATABASES['default']['NAME'] = ':memory:'