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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:38:53+00:00 2026-06-04T01:38:53+00:00

I followed a bit the steps on Django User Profiles – Simple yet powerful

  • 0

I followed a bit the steps on Django User Profiles – Simple yet powerful.

Not quite the same because I am in the middle of developing the idea.
From this site I used in particular, also this line:

User.profile = property(lambda u:
UserProfile.objects.get_or_create(user=u)[0])

I was getting always an error message on creating the object, typically
“XX” may not be null. I solved part of the problems by playing with models
and (in my present case) sqliteman. Till I got the same
message on the id: “xxx.id may not be null”.

On the net I found a description of a possible solution which involved doing a reset
of the database, which I was not that happy to do. In particular because for the
different solutions, it might have involved the reset of the application db.

But because the UserProfile model was kinda new and till now empty,
I played with it on the DB directly and made an hand made drop of the table and
ask syncdb to rebuilt it. (kinda risky thought).

Now this is the diff of the sqlite dump:

294,298c290,294
< CREATE TABLE "myt_userdata" (
<     "id" integer NOT NULL PRIMARY KEY,
<     "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id"),
<     "url" varchar(200),
<     "birthday" datetime
---
> CREATE TABLE myt_userdata (
>     "id" INTEGER NOT NULL,
>     "user_id" INTEGER NOT NULL,
>     "url" VARCHAR(200),
>     "birthday" DATETIME

Please note that both versions are generated by django. The “>” version was generated with a simple model definition which had indeed the connection with the user table via:

user = models.ForeignKey(User, unique=True)

The new “<” version has much more information and it is working.

My question:

Why Django complains about an myt_userdata.id may not be null?

The subsidiary question:

Does Django tries to relate to the underline db structure, how?
(for example the not NULL message comes from the model or from the DB?)

The additional question:

I have been a bit reluctant to the use south: Too complicated, additional modules
which I might have to care between devel and production and maybe not that easy
if I want to switch DB engine (I am using sqlite only at devel stage, I plan to move to
mysql).

Probably south might have worked in this case. Would it work? would you suggest its use
anyway?

Edited FIY:

This is my last model (the working one):

class UserData(models.Model):

    user = models.ForeignKey(User, unique=True)

    url = models.URLField("Website", blank=True, null=True)

    birthday = models.DateTimeField('Birthday', blank=True, null=True)

    def __unicode__(self):
        return self.user.username

User.profile = property(lambda u: UserData.objects.get_or_create(user=u,defaults={'birthday': '1970-01-01 00:00:00'})[0])
  • 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-04T01:38:55+00:00Added an answer on June 4, 2026 at 1:38 am

    Why Django complains about an myt_userdata.id may not be null?

    Because id is not a primary key and is not populated automatically though. Also, you don’t provide it on model creation, so DB does not know what to do.

    Does Django tries to relate to the underline db structure, how? (for example the not NULL message comes from the model or from the DB?)

    It’s an error from DB, not from Django.

    You can use sql command to understan what exactly is executed on syncdb. Variant above seems to be correct table definition made from correct Django model, and I have no ide how have you got a variant below. Write a correct and clear model, and you’ll get correct and working table scheme after syncdb

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

Sidebar

Related Questions

I followed this tutorial (there's a bit more than what's listed here because in
I followed along with this tutorial ( http://www.bit-101.com/blog/?p=1861 ) and noticed that upon saving
I followed the tutorial for setting up simple authentication (http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html) and I am having
Ok, I've searched all over and have spent quite a bit of my time
I followed the steps in: http://lennybacon.com/2010/10/18/UltimateGuideToSpeedUpVisualStudio.aspx to make my Visual Studio 2010 faster, including
I have followed some advices I got here today and would need a bit
I have ADT loaded onto classic Eclipse. I followed the steps from the Android
I followed these steps to be able to debug in the .Net framework code.
I installed the https://github.com/pennersr/django-allauth package via pip. I followed the README.rst and after a
i have followed these steps to install Access Database Engine, configure the ODBC data

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.