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 9048263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:07:05+00:00 2026-06-16T12:07:05+00:00

I set default value as 0 in foreign key field in Django model. But

  • 0

I set default value as 0 in foreign key field in Django model. But it is raising IntigrityError (1048, “Column ‘country_id’ cannot be null”)

Hi, I have code like:

class TestModel(models):
    name = models.CharField(max_length=255, blank=True)
    reg_from = models.CharField(max_length=255, blank=True)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES, blank=True, null=True)
    country = models.ForeignKey(Country, blank=True, default=0)

For some reason, while saving TestModel, I can’t provide country information. I would like to update that later.

Krish

  • 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-16T12:07:06+00:00Added an answer on June 16, 2026 at 12:07 pm

    I made field null as quick and dirty solution.

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

Sidebar

Related Questions

i want to set the default value in a sql server 2005 datetime field
I'm trying to set a default value for a search field. The idea is
Is there any way to set the default value for a column as an
I want to set the default value of my forms 'author' field (models.ForeignKey(User)) to
I have added a foreign key to a user to a model, but when
Hi, I have a table that contains a foreign key value(id). This field is
I have a DateTime field that I want to set to a default value
how can i set default value in sonata admin bundle the data option is
How to set default VALUE in SubQuery result using mysql SELECT p.`id`, p.`name`, p.`class_name`,
When I set a default value formula for a date parameter in SSRS, such

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.