John Medosa
John Medosa

Reputation: 3

django ValueError: source code string cannot contain null bytes

I want to create an app but I want to use my existing tables so I run inspectdb command on terminal

from django.db import models

class OhrmJobTitle(models.Model):
job_title = models.CharField(max_length=100)
job_description = models.CharField(max_length=400, blank=True, null=True)
note = models.CharField(max_length=400, blank=True, null=True)
is_deleted = models.IntegerField(blank=True, null=True)

class Meta:
    managed = False
    db_table = 'ohrm_job_title'

generated by inspectdb based on my table

I'm getting an error trying to runserver command

below is the traceback if someone is interested

Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in 
_bootstrap_inner
self.run()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in 
run
self._target(*self._args, **self._kwargs)
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site- 
packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site- 
packages\django\core\management\commands\runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site- 
packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site- 
packages\django\core\management\__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site- 
packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site-packages\django\__init__.py", line 
24, in setup 
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site-packages\django\apps\registry.py", 
line 116, in populate
app_config.import_models()
File "C:\Users\user\PycharmProjects\hrmorms\venv\lib\site-packages\django\apps\config.py", 
line 304, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py", line 
126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 879, in exec_module
File "<frozen importlib._bootstrap_external>", line 1017, in get_code
File "<frozen importlib._bootstrap_external>", line 947, in source_to_code
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes

I never tried to use "Database First or Legacy Database" approach before. I dont have anything else right now its just my models.py

Upvotes: 0

Views: 1620

Answers (1)

John Medosa
John Medosa

Reputation: 3

I just found out my old models.py uses encoding UTF-8 while the file generated by inspectdb is not, Maybe someone will find this useful

Upvotes: 0

Related Questions