首頁>Club>
4
回覆列表
  • 1 # 用戶6313219638313

    ValueError:"<Entry:django the newest techology>" need to have a value for field 'id' before this many-to-many relationship can be used

    因為entry沒有被寫入到數據庫,訪問它的authors屬性會有問題

    解決辦法:

    先設置好Entry對象的其他非空屬性,並保存,再設置多對多關系:

    entry = Entry()

    entry.headline = 'headline'

    entry.body_text = "body text"

    ...

    entry.save()

    entry.authors.add(author)

    entry.save()

  • 中秋節和大豐收的關聯?
  • 西遊記唐僧橫渡冰面妖怪是誰?