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

  • SEARCH
  • Home
  • 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 8243647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:35:11+00:00 2026-06-07T21:35:11+00:00

I have an unusual case. In my models.py, I have an Event element, and

  • 0

I have an unusual case. In my models.py, I have an Event element, and two different types of user elements that refer to it as seen below.

class User(models.Model):

     attending = models.ManyToManyField('Event', related_name='User_attending')
     hosting = models.ForeignKey('Event', related_name='User_hosting')

     username = models.CharField(max_length=40)


class Event(models.Model):
     #event title
     title = models.CharField(max_length=200)
     #time created
     created = models.DateField('Date Created',auto_now_add=True)

In my views.py, I when I want to create a user, I have some of the following:

    user = User()
    user.username = ""
    user.gender = 0
    user.fName = ""
    user.lName = ""
    ....
    user.save

This is when my browser yells at me and says:

Integrity Error,
list_user.hosting_id may not be NULL

Any ideas for a way around this without creating an Event element right there?

  • 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-07T21:35:13+00:00Added an answer on June 7, 2026 at 9:35 pm

    It appears you want to create a User without giving hosting a value. You can do this by adding blank=True, null=True to the field:

    hosting = models.ForeignKey('Event', related_name='User_hosting',
                                blank=True, null=True)
    

    You’ll also need to add a migration to fix the database (as the ability to have an empty field needs to be allowed by the database). I suggest using South for this purpose.

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

Sidebar

Related Questions

I have a application that need event handling on a unusual way. For my
I'm trying to shred XML files that have an unusual layout, because items are
We have a somewhat unusual c app in that it is a database of
I have an unusual problem. Let's consider such models (taken from django docs): class
I have an unusual environment in a project where I have many files that
I have an unusual use-case I'm trying to code for. The goal is this:
I have unusual format of XML as below example <mainmenu> <menu caption=File> <menuitem caption=New
The C standard allows pointers to different types to have different sizes, e.g. sizeof(char*)
I have an unusual need. I have five input checkboxes that look like this:
We have an unusual case, a try-catch block inside another try-catch block. Both catch

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.