Django – Value error when adding app name in 'INSTALLED APPS'

Question:

When i add my app name in INSTALLED APPS inside settings.py file, i got the following error and its removed when i erase my app name from settings. What is the problem here?

Unhandled exception in thread started by <function check_errors. 
<locals>.wrapper at 0x0000007BFA7BB598>
Traceback (most recent call last):
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoutilsautoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangocoremanagementcommandsrunserver.py", line 117, in 
inner_run autoreload.raise_last_exception()
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoutilsautoreload.py", line 250, in raise_last_exception
six.reraise(*_exception)
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoutilssix.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoutilsautoreload.py", line 227, in wrapper
fn(*args, **kwargs)
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjango__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoappsregistry.py", line 108, in populate
app_config.import_models()
File "C:UserspostgresAppDataLocalProgramsPythonPython36libsite- 
packagesdjangoappsconfig.py", line 202, in import_models
self.models_module = import_module(models_module_name)

return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes
Asked By: Aisha atique

||

Answers:

I met almost same problem with you.
Finally, I found my problem is from the models.py in apps, which is generated by the command ‘python manage.py inspectdb > models.py’.
This models.py is not utf-8 Format. you can open it by notepad++ and change the Format and save it. Then, everything is ok.

Answered By: Xiaofeifei
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.