title: Django profile id may not not null using get_or_create, how does it relate to the db?
body: <p>I followed a bit the steps on <a href="http://www.turnkeylinux.org/blog/django-profile" rel="nofollow">Django User Profiles - Simple yet powerful</a>.</p>
  
  <p>Not quite the same because I am in the middle of developing the idea.
  From this site I used in particular, also this line:</p>
  
  <blockquote>
    <p>User.profile = property(lambda u:
    UserProfile.objects.get_or_create(user=u)[0])</p>
  </blockquote>
  
  <p>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".</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>Now this is the diff of the sqlite dump:</p>
  
  <pre><code>294,298c290,294
  &lt; CREATE TABLE "myt_userdata" (
  &lt;     "id" integer NOT NULL PRIMARY KEY,
  &lt;     "user_id" integer NOT NULL UNIQUE REFERENCES "auth_user" ("id"),
  &lt;     "url" varchar(200),
  &lt;     "birthday" datetime
  ---
  &gt; CREATE TABLE myt_userdata (
  &gt;     "id" INTEGER NOT NULL,
  &gt;     "user_id" INTEGER NOT NULL,
  &gt;     "url" VARCHAR(200),
  &gt;     "birthday" DATETIME
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>user = models.ForeignKey(User, unique=True)
  </code></pre>
  
  <p>The new "&lt;" version has much more information and it is working.</p>
  
  <p>My question:</p>
  
  <p>Why Django complains about an myt_userdata.id may not be null?</p>
  
  <p>The subsidiary question:</p>
  
  <p>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?)</p>
  
  <p>The additional question:</p>
  
  <p>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).</p>
  
  <p>Probably south might have worked in this case. Would it work? would you suggest its use
  anyway?</p>
  
  <p>Edited FIY:</p>
  
  <p>This is my last model (the working one):</p>
  
  <pre><code>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])
  </code></pre>