Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8267877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:41:26+00:00 2026-06-08T05:41:26+00:00

These are my models: class war(models.Model): title = models.CharField(max_length=20) class option(models.Model): warval =models.ForeignKey(war) value

  • 0

These are my models:

class war(models.Model):
    title = models.CharField(max_length=20)

class option(models.Model):
    warval =models.ForeignKey(war)
    value = models.CharField(max_length=10)

class warform(ModelForm):
    class Meta:
        model = war

class option_form(ModelForm):
    class Meta:
        model = option
    exclude = ('warval')

And this is the view which handles creation of option:

def warhandler(request,war_id):
    f=modelformset_factory(option,form=option_form)
    wobj=get_object_or_404(war,pk=war_id)
    if request.method == 'POST':
        formset = f(request.POST,queryset=option.objects.filter(warval=wobj))
        if formset.is_valid():
            formset.save()
            return HttpResponse("Saved!check your model")   
        else:
            return render_to_response("formset.html",RequestContext(request,{"set":formset}))
    else:
        formset = f(queryset=option.objects.filter(warval=wobj))
        print(formset)
        return render_to_response("formset.html",RequestContext(request,{"set":formset,"war":wobj}))

So when I submit the form to this view,I get the following error:

Exception Type: IntegrityError
Exception Value: hit_option.warval_id may not be NULL

I know what this error is and why it is coming but how can I remove this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:41:27+00:00Added an answer on June 8, 2026 at 5:41 am

    Make warval a non-required field with

    class option(models.Model):
        warval =models.ForeignKey(war, null=True)
        value = models.CharField(max_length=10)
    

    or define formset.warval before saving, make a default value…

    edit:

    read here and here for using subset of fields on a form and saving.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have these models: class A(models.Model): name = models.CharField(max_length=32) b = models.ForeignKey(B,
I have these models: class Person(models.Model): name=models.CharField(max_length=100) family=models.CharField(max_length=100) class MailContact(models.Model): person=models.ForeignKey(Person) email=models.CharField(max_length=100) #some fields
I currently have these models: class Category(models.Model): name = models.CharField(max_length=200) parent = models.ForeignKey('self', blank=True,
These are my models class Review(models.Model): reviewHeader = models.CharField(null=False,default=,max_length=200) class ReviewRate(models.Model): review = models.ForeignKey(CompanyReview,null=False,default=0)
I have these models set up in Django: class SourceBusiness(models.Model): source = models.CharField(max_length=100) ...(other
I have these models: class Supplier(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return u"%s" %
I have these models: class Projects(models.Model): projectName =models.CharField(max_length = 100,unique=True,db_index=True) projectManager = EmbeddedModelField('Users') class
I have these models: class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100)
Consider these pseudo models: class City(models.Model): name = models.CharField() region = models.ForeignKey(Region) class Region(models.Model):
I have these Django models: class Group(models.Model): name = models.CharField(max_length=100) parent_group = models.ManyToManyField("self", blank=True)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.