Discussion:
loaddata and auto_now_add=True
Reikje
2011-10-03 07:43:35 UTC
Permalink
Hi, I have a test fixture file which I use in unit tests. In some
Models I have date fields defined like this:
models.DateTimeField(auto_now_add=True) for which I don't specify
values in the fixture file (users.json). This works well as part of
testing but when I want to load the fixture into the real database
using the loaddata command, it will complain about these fields being
null, i.e. Warning: Column 'last_seen_at' cannot be null

Whats the difference between running the fixture file as part of the
test suite and loading it using loaddata. I guess I can work around
this by adding values for these fields but I am lazy :)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Phang Mulianto
2011-10-03 08:53:52 UTC
Permalink
i think bcoz load data does not use the orm api..while your test use orm to
insert data..
Post by Reikje
Hi, I have a test fixture file which I use in unit tests. In some
models.DateTimeField(auto_now_add=True) for which I don't specify
values in the fixture file (users.json). This works well as part of
testing but when I want to load the fixture into the real database
using the loaddata command, it will complain about these fields being
null, i.e. Warning: Column 'last_seen_at' cannot be null
Whats the difference between running the fixture file as part of the
test suite and loading it using loaddata. I guess I can work around
this by adding values for these fields but I am lazy :)
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
Post by Reikje
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Reikje
2011-10-04 06:45:41 UTC
Permalink
Ok so bottomline is, you have to add values for this kind of fields if
you want to use the fixture from both, tests and loaddata?
Post by Phang Mulianto
i think bcoz load data does not use the orm api..while your test use orm to
insert data..
Post by Reikje
models.DateTimeField(auto_now_add=True) for which I don't specify
values in the fixture file (users.json). This works well as part of
testing but when I want to load the fixture into the real database
using the loaddata command, it will complain about these fields being
null, i.e. Warning: Column 'last_seen_at' cannot be null
Whats the difference between running the fixture file as part of the
test suite and loading it using loaddata. I guess I can work around
this by adding values for these fields but I am lazy :)
--
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Russell Keith-Magee
2011-10-04 13:32:19 UTC
Permalink
A fixture is intended to be a full and complete copy of what you want
in the database, including *all* date/timestamps. If you want data to
be created with creation/update times that reflect the time at which
the test was executed, then you need to create that data in the
setUp() method of your test, or use the setUp() method to modify the
object loaded by the fixture.

Yours,
Russ Magee %-)
Post by Reikje
Ok so bottomline is, you have to add values for this kind of fields if
you want to use the fixture from both, tests and loaddata?
Post by Phang Mulianto
i think bcoz load data does not use the orm api..while your test use orm to
insert data..
Post by Reikje
models.DateTimeField(auto_now_add=True) for which I don't specify
values in the fixture file (users.json). This works well as part of
testing but when I want to load the fixture into the real database
using the loaddata command, it will complain about these fields being
null, i.e. Warning: Column 'last_seen_at' cannot be null
Whats the difference between running the fixture file as part of the
test suite and loading it using loaddata. I guess I can work around
this by adding values for these fields but I am lazy :)
--
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Loading...