Django ModelForm not saving data to database

前端 未结 6 2085
温柔的废话
温柔的废话 2021-02-10 05:53

A Django beginner here having a lot of trouble getting forms working. Yes I\'ve worked through the tutorial and browsed the web a lot - what I have is mix of what I\'m finding h

6条回答
  •  北恋
    北恋 (楼主)
    2021-02-10 06:18

    This is kind of old thread, but I hope this will help someone. I've been struggling with similar issue, I initiated object from db, updated field, called save() function and nothing happened.

    user = User.objects.get(username = example_string)
    user.userprofile.accepted_terms = True
    user.userprofile.save()
    

    The field accepted_terms have been added lately and that was the issue. First try python manage.py makemigrations and python manage.py migrate, if this does not help you need to flush the database.

    Solution in my case was flushing the database.

提交回复
热议问题