问题一:
在执行python manage.py makemigrations learning_logs时,系统会报错,提示:TypeError: __init__() missing 1 required positional argument: 'on_delete'
缺少参数,修改指定外键的方式,设置级联更新参数:
topic = models.ForeignKey(Topic, on_delete=models.CASCADE)
问题二:
?: (urls.W005) URL namespace 'learning_logs' isn't unique. You may not be able to reverse all URLs in this namespace
根目录的urls.py文件中
from django.contrib import admin
from django.urls import path
from django.urls import include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('learning_logs.urls', namespace='learning_logs')),
path('topics/', include('learning_logs.urls', namespace='learning_logs')), #删除此行即可,只需要添加一次命名空间
#你包括learning_logs.urls两次。虽然这在一个方向上工作正常,但它无法逆转,因为会有两个结果。基于反向映射器
#的所有函数将无法按预期工作。
]
问题三:
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x0000000003CC9D90>
Traceback (most recent call last):
File "E:\python\learning_log\ll_env\lib\site-packages\django\utils\autoreload.
py", line 225, in wrapper
fn(*args, **kwargs)
File "E:\python\learning_log\ll_env\lib\site-packages\django\core\management\c
ommands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "E:\python\learning_log\ll_env\lib\site-packages\django\core\management\b
ase.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "E:\python\learning_log\ll_env\lib\site-packages\django\core\management\b
ase.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "E:\python\learning_log\ll_env\lib\site-packages\django\core\checks\regis
try.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "E:\python\learning_log\ll_env\lib\site-packages\django\core\checks\urls.
py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(re