Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Initial data fixtures and auto_now_add=True
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andrew Turner  
View profile  
 More options Jan 19 2010, 8:36 am
From: Andrew Turner <acturne...@gmail.com>
Date: Tue, 19 Jan 2010 05:36:25 -0800 (PST)
Local: Tues, Jan 19 2010 8:36 am
Subject: Initial data fixtures and auto_now_add=True
I have an initial_data.json file which provides some, er, initial data
whenever I run syncdb. One of my models has a DateTimeField with
auto_now_add=True. The data is loaded first time round, but on
subsequent syncdbs, I get "IntegrityError: posts_entry.pub_date may
not be NULL".

Is this the expected behaviour? Note that all is fine if the field is
changed to auto_now=True instead.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Turner  
View profile  
 More options Feb 2 2010, 2:58 am
From: Andrew Turner <acturne...@gmail.com>
Date: Mon, 1 Feb 2010 23:58:22 -0800 (PST)
Local: Tues, Feb 2 2010 2:58 am
Subject: Re: Initial data fixtures and auto_now_add=True
On Jan 19, 1:36 pm, Andrew Turner <acturne...@gmail.com> wrote:

> I have an initial_data.json file which provides some, er, initial data
> whenever I run syncdb. One of my models has a DateTimeField with
> auto_now_add=True. The data is loaded first time round, but on
> subsequent syncdbs, I get "IntegrityError: posts_entry.pub_date may
> not be NULL".

Anyone? Is this behaviour expected, or should I file a bug?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Feb 2 2010, 3:07 am
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Tue, 2 Feb 2010 16:07:30 +0800
Local: Tues, Feb 2 2010 3:07 am
Subject: Re: Initial data fixtures and auto_now_add=True

On Tue, Feb 2, 2010 at 3:58 PM, Andrew Turner <acturne...@gmail.com> wrote:
> On Jan 19, 1:36 pm, Andrew Turner <acturne...@gmail.com> wrote:
>> I have an initial_data.json file which provides some, er, initial data
>> whenever I run syncdb. One of my models has a DateTimeField with
>> auto_now_add=True. The data is loaded first time round, but on
>> subsequent syncdbs, I get "IntegrityError: posts_entry.pub_date may
>> not be NULL".

> Anyone? Is this behaviour expected, or should I file a bug?

Well, it's difficult to know what is expected without more details. I
can't think of any obvious reason why a fixture should fail on the
*second* syncdb that doesn't also involve you doing something
unexpected to your data in the interim. However, without any details
of what else is in your models, or what else you have done to your
data, it's impossible to say if you've found a bug or if you're doing
something wrong.

It is possible you've found a bug, but in order to verify that, we
need a minimal example that reproduces the problem - that is, the
simplest possible model and fixture combination that fails on the
second syncdb like you describe.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Turner  
View profile  
 More options Feb 2 2010, 4:12 am
From: Andrew Turner <acturne...@gmail.com>
Date: Tue, 2 Feb 2010 01:12:29 -0800 (PST)
Local: Tues, Feb 2 2010 4:12 am
Subject: Re: Initial data fixtures and auto_now_add=True
On Feb 2, 8:07 am, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

> It is possible you've found a bug, but in order to verify that, we
> need a minimal example that reproduces the problem - that is, the
> simplest possible model and fixture combination that fails on the
> second syncdb like you describe.

Thanks for the reply.

Here is a simple initial_data.json:-

[
    {
        "model": "posts.entry",
        "pk": 1,
        "fields": {
            "content": "This is the content"
        }
    }
]

And here is my models.py:-

from django.db import models

class Entry(models.Model):
    content = models.CharField(max_length=250)
    pub_date = models.DateTimeField(auto_now_add=True, editable=False)

First time syncdb is run, the fixture is correctly loaded, subsequent
runs result in the aforementioned error. Tested on Django 1.1.1 and
1.2alpha.

Thanks,
Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Feb 2 2010, 8:29 am
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Tue, 2 Feb 2010 21:29:56 +0800
Local: Tues, Feb 2 2010 8:29 am
Subject: Re: Initial data fixtures and auto_now_add=True

It appears you have found a bug (what is worse - one that I thought we
were testing for).

The cause of the problem is your initial fixture. Django doesn't
listen to auto_now_add or auto_now fields on fixture loading - fixture
objects are saved in "raw" mode, so it is assumed that the fixture
should have data for all the fields. In this case, your fixture is
missing a definition for pub_date, so on the second sync, you are
getting the error I would expect - that the null value in the column
isn't allowed.

However, you should also be getting that error on the first syncdb.
For some reason, the raw mode save isn't preventing the default value
from being initialized. This is a bug, which I've opened as #12753.

Of course, the immediate workaround for you is to include a datetime
in your fixture.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Turner  
View profile  
 More options Feb 2 2010, 8:41 am
From: Andrew Turner <acturne...@gmail.com>
Date: Tue, 2 Feb 2010 05:41:48 -0800 (PST)
Local: Tues, Feb 2 2010 8:41 am
Subject: Re: Initial data fixtures and auto_now_add=True
On Feb 2, 1:29 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

> The cause of the problem is your initial fixture. Django doesn't
> listen to auto_now_add or auto_now fields on fixture loading - fixture
> objects are saved in "raw" mode, so it is assumed that the fixture
> should have data for all the fields. In this case, your fixture is
> missing a definition for pub_date, so on the second sync, you are
> getting the error I would expect - that the null value in the column
> isn't allowed.

I see. As stated in my original post, syncdb works the second time
round when auto_now=True is used. Surely that shouldn't work at all
either?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Russell Keith-Magee  
View profile  
 More options Feb 2 2010, 8:45 am
From: Russell Keith-Magee <freakboy3...@gmail.com>
Date: Tue, 2 Feb 2010 21:45:28 +0800
Local: Tues, Feb 2 2010 8:45 am
Subject: Re: Initial data fixtures and auto_now_add=True

On Tue, Feb 2, 2010 at 9:41 PM, Andrew Turner <acturne...@gmail.com> wrote:
> On Feb 2, 1:29 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:
>> The cause of the problem is your initial fixture. Django doesn't
>> listen to auto_now_add or auto_now fields on fixture loading - fixture
>> objects are saved in "raw" mode, so it is assumed that the fixture
>> should have data for all the fields. In this case, your fixture is
>> missing a definition for pub_date, so on the second sync, you are
>> getting the error I would expect - that the null value in the column
>> isn't allowed.

> I see. As stated in my original post, syncdb works the second time
> round when auto_now=True is used. Surely that shouldn't work at all
> either?

Correct. I'm guessing that the same thing is happening - the default
value is being used because the fixture doesn't specify a value. Feel
free to update the ticket so the auto_now case isn't forgotten.

Yours,
Russ Magee %-)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrew Turner  
View profile  
 More options Feb 2 2010, 9:07 am
From: Andrew Turner <acturne...@gmail.com>
Date: Tue, 2 Feb 2010 06:07:54 -0800 (PST)
Local: Tues, Feb 2 2010 9:07 am
Subject: Re: Initial data fixtures and auto_now_add=True
On Feb 2, 1:45 pm, Russell Keith-Magee <freakboy3...@gmail.com> wrote:

> Correct. I'm guessing that the same thing is happening - the default
> value is being used because the fixture doesn't specify a value. Feel
> free to update the ticket so the auto_now case isn't forgotten.

Done ;)

Kind regards,
Andrew


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »