簡體   English   中英

django model 在具有外鍵的字段中沒有列錯誤

[英]django model no column error in a field with foreign key

我有自定義用戶 model

class User(AbstractUser):  
     model fields 

和另一個 model 具有與用戶外鍵關系的字段

class Comment(models.Model):
    writer = models.ForeignKey(User,on_delete=models.CASCADE,null=True,related_name='comment_writer')
    contents = models.TextField(max_length=300,null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

但是當我進行遷移並遷移應用程序和項目時,我仍然在管理頁面上收到錯誤消息

OperationalError at /admin/User/comment/ no such column: User_comment.writer_id Request Method: GET Request URL: http://localhost:8000/admin/User/comment/ Django Version: 2.2.3 Exception Type: OperationalError Exception Value:
沒有這樣的列:User_comment.writer_id 異常位置:/usr/local/lib/python3.6/dist-packages/django/db/backends/sqlite3/base.py 在執行中,第 383 行 Python 可執行文件:/usr/bin/python3 Python 版本:3.6.9 Python 路徑:
['/home/potentad/Documents/timesello', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', ' /home/potentad/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/local/lib/python3.6/dist-包/onedrived-2.0.0-py3.6.egg','/usr/local/lib/python3.6/dist-packages/zgitignore-1.0.0-py3.6.egg','/usr/local/ lib/python3.6/dist-packages/tabulate-0.8.7-py3.6.egg', '/usr/local/lib/python3.6/dist-packages/psutil-5.7.0-py3.6-linux -x86_64.egg', '/usr/lib/python3/dist-packages'] 服務器時間:2020 年 5 月 22 日星期五 23:20:23 +0000

出了什么問題,我該怎么辦?

你能運行這條線嗎

python manage.py makemigrations

python manage.py migrate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM