所有這些錯誤都是在我執行 models.py 時才開始發生的,據我所知,我沒有寫錯任何代碼。以前的“makemigrations”有效。似乎很多 Traceback 錯誤與 models.py 無關。(希望這些很容易閱讀,抱歉)回溯錯誤:追溯(最近一次通話):main() 中的文件“manage.py”,第 21 行主 execute_from_command_line(sys.argv) 中的文件“manage.py”,第 17 行文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django /core/management/ init .py”,第 401 行,在 execute_from_command_line utility.execute()文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/core/management/init.py ”,第377行,在execute django.setup()文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/ init .py”,第 24 行,在設置 appspopulate(settings.INSTALLED_APPS)文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/apps/registry.py”,第 114 行,填充 app_config.import_models()文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/apps/config.py”,第 211 行,在 import_models 中 self.models_module = import_module(models_module_name)文件“/usr/lib/python3.6/importlib/init .py”,第 126 行,在import_module return _bootstrap._gcd_import(name[level:], package, level)_gcd_import 中的文件“”,第 994 行文件“”,第 971 行,在 _find_and_load文件“”,第 955 行,在 _find_and_load_unlocked文件“”,第 665 行,在 _load_unlockedexec_module 中的文件“”,第 678 行文件“”,第 219 行,在 _call_with_frames_removed 中文件“/home/alatimer/Environments/djangoproject/blog/models.py”,第 6 行,在類 Post(models.Model) 中:文件“/home/alatimer/Environments/djangoproject/blog/models.py”,第 9 行,在 Post date_posted = models.DateTimeField(defualt=timezone.now)文件“/home/alatimer/Environments/DjangoTutorial_env/lib/python3.6/site-packages/django/db/models/fields/init .py”,第 1107 行,在init super () 中。init (verbose_name, name, **kwargs)TypeError: init () 得到了一個意外的關鍵字參數 'defualt'models.py:from django.db import modelsfrom django.utils import timezonefrom django.contrib.auth.models import User
3 回答

揚帆大魚
TA貢獻1799條經驗 獲得超9個贊
我希望這是為了
date_posted = models.DateTimeField(defualt=timezone.now)
.
嘗試在沒有此字段的情況下遷移模型。如果遷移則嘗試
date_posted = models.DateTimeField(default=timezone.now,blank=True, null=True)

溫溫醬
TA貢獻1752條經驗 獲得超4個贊
好吧,錯誤實際上說明了一切(最后一行):
TypeError: init() 得到了一個意外的關鍵字參數'defualt'
因此,在您的 models.py 中,應更正此行:
date_posted = models.DateTimeField(defualt=timezone.now)
它不是默認的,它是默認的。你打錯字了!

拉風的咖菲貓
TA貢獻1995條經驗 獲得超2個贊
嘗試
class Post(models.Model):
title = models.CharField(max_length=100, blank=True, null=True)
content = models.TextField(blank=True, null=True)
date_posted = models.DateTimeField(defualt=timezone.now, blank=True, null=True)
author = models.ForeignKey(User, on_delete=models.CASCADE)
添加回答
舉報
0/150
提交
取消