我刚刚安装了Django,并在settings.py中将数据库从sqlite3更改为mysql,但是当我运行服务器时,偶尔会出现“ ValueError:嵌入式空字节”。 我该怎么办?
(myproject) bash-3.2$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 577, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 562, in start_django
reloader.run(django_main_thread)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 280, in run
self.run_loop()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 286, in run_loop
next(ticker)
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 326, in tick
for filepath, mtime in self.snapshot_files():
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 342, in snapshot_files
for file in self.watched_files():
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 241, in watched_files
yield from iter_all_python_module_files()
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/Users/mydir/.virtualenvs/myproject/lib/python3.6/site-packages/django/utils/autoreload.py", line 132, in iter_modules_and_files
results.add(path.resolve().absolute())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 1122, in resolve
s = self._flavour.resolve(self, strict=strict)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 349, in resolve
return _resolve(base, str(path)) or sep
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 331, in _resolve
target = accessor.readlink(newpath)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pathlib.py", line 443, in readlink
return os.readlink(path)
ValueError: embedded null byte
答案 0 :(得分:1)
我遇到了同样的问题,调试它似乎是由于在v2.2.0中引入了watchman所致,因为降级到v1.9.0会将其删除。
奇怪的是,有时服务器会启动,但并不是每次都不会出现该错误,但是我相当确定这是由于虚拟环境造成的。
修复:
禁用重新加载(不理想)
python manage.py runserver --noreload
创建一个看守配置并忽略venv
https://docs.djangoproject.com/en/2.2/ref/django-admin/#runserver
https://facebook.github.io/watchman/docs/config.html#ignore_dirs
但是我实际上无法让ignore_dirs工作...
Django票证
答案 1 :(得分:0)
这是我的mysql设置。
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'novoair',
'USER': 'root',
'PASSWORD': 'root@123',
'HOST': 'localhost',
'PORT': '3306',
},
}
用户名密码主机端口设置为您的