Try not setting any value to the field, it should be saved with the default value
There are a ton of answers to this question out there - if you can wade through all the ones that refer to forms and not models. The consensus seems to be that datetime has to be set to both blank=true and null=true. And when I put in one test row of data manually through the admin, I could leave my datetime field blank with no problems. But when I tried to load the 89 other instances through a fixture, I got error after error.As near as I can tell, if you leave a json value blank, loaddata says it isn't a json document. But if you put the empty string, '', Null, None, "Null", "None" or "0000-00-00" in there, it is rejected as not valid date format. Therefore, it seems there is no way to do this through a fixture. My question: Is this correct? If so, is there any alternative to doing it all manually? Thanks.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/db367bcf-8cbf-4001-8976-f602e93576d5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
There are a ton of answers to this question out there - if you can wade through all the ones that refer to forms and not models. The consensus seems to be that datetime has to be set to both blank=true and null=true. And when I put in one test row of data manually through the admin, I could leave my datetime field blank with no problems. But when I tried to load the 89 other instances through a fixture, I got error after error.
As near as I can tell, if you leave a json value blank, loaddata says it isn't a json document. But if you put the empty string, '', Null, None, "Null", "None" or "0000-00-00" in there, it is rejected as not valid date format. Therefore, it seems there is no way to do this through a fixture. My question: Is this correct? If so, is there any alternative to doing it all manually? Thanks.
First, thank you to both Avraham and James. In my view, it isn't said often enough on the internet, and I've had many questions go without a response at all. So please understand that I mean it very much when I say I deeply appreciate the time you took to help me.
Now as to the matter at hand: The field in question is 'sunsetdate', referring to the date something ends. It must be optional since most of my objects/data don't, or haven't, ended. The first time I tried this I had the empty string, '', in all rows in that column.
(cannon)malikarumi@Tetuoan2:~/Projects/cannon/jamf$ python manage.py loaddata essell/fixtures/test22byhand.json
Traceback (most recent call last):
File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/core/serializers/python.py", line 174, in Deserializer
raise base.DeserializationError.WithData(e, d['model'], d.get('pk'), field_value)
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': [u"'' value has an invalid date format. It must be in YYYY-MM-DD format."]: (essell.Code:pk=None) field_value was ''
I replaced “”, - the empty string - with ',', that is, nothing, no string, no quote, nothing but the comma
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': No JSON object could be decoded
So now I assume this is because there are no quotes on sunsetdate. Note how that one error in that one field makes the whole document 'not json'.
Now I have to put the date in the way they want it, which is not what I want but not the end of the world since I don't have to display this field if there is no actual sunset date.
File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/core/serializers/python.py", line 174, in Deserializer
raise base.DeserializationError.WithData(e, d['model'], d.get('pk'), field_value)
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': [u"'null' value has an invalid date format. It must be in YYYY-MM-DD format."]: (essell.Code:pk=None) field_value was 'null'
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': [u"'0000-00-00' value has the correct format (YYYY-MM-DD) but it is an invalid date."]: (essell.Code:pk=None) field_value was '0000-00-00'
Last night before posting I hacked serializers/python.py to make an exception for sunsetdate, and that apparently worked, but now I have this:
File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2390, in get_db_prep_value
value = uuid.UUID(value)
File "/usr/lib/python2.7/uuid.py", line 134, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': badly formed hexadecimal UUID string
The only uuid currently in this fixture is the one I got from Django when I put another model (only one row) in with a fixture (no date field) and it worked. I needed the uuid of that object to put into the foreign key of the model I am having trouble with now.
Finally, this morning after reading your responses I decided to try putting in null with no comma, since I had already tried it with no quotes, and of course that didn't work. But then in fooling with it I put null in right next to the colon, with no spaces or quotes, followed by a comma, and this time null turned blue in my code editor, which suggests it was working. But then I got the 'badly formed hexadecimal UUID string error again.
In sum, there is a special syntax to using null which is not obvious, but thanks for making me take another look and try again. The uuid error seems to be something else. There is a bugfix on github from November of 2014, so I don't (yet) know why I'm having this issue. I may post that later as a separate question. Thanks again!
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW%3Ddm%3DM9Eh10Y8zcB%2Bvjx6E0UQC6a0mzsyyELmb2x2qzA%40mail.gmail.com.
Last night before posting I hacked serializers/python.py to make an exception for sunsetdate, and that apparently worked, but now I have this:
File "/home/malikarumi/Projects/cannon/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 2390, in get_db_prep_value
value = uuid.UUID(value)
File "/usr/lib/python2.7/uuid.py", line 134, in __init__
raise ValueError('badly formed hexadecimal UUID string')
ValueError: Problem installing fixture '/home/malikarumi/Projects/cannon/jamf/essell/fixtures/test22byhand.json': badly formed hexadecimal UUID string
The only uuid currently in this fixture is the one I got from Django when I put another model (only one row) in with a fixture (no date field) and it worked. I needed the uuid of that object to put into the foreign key of the model I am having trouble with now.
Finally, this morning after reading your responses I decided to try putting in null with no comma, since I had already tried it with no quotes, and of course that didn't work. But then in fooling with it I put null in right next to the colon, with no spaces or quotes, followed by a comma, and this time null turned blue in my code editor, which suggests it was working. But then I got the 'badly formed hexadecimal UUID string error again.
In sum, there is a special syntax to using null which is not obvious, but thanks for making me take another look and try again. The uuid error seems to be something else. There is a bugfix on github from November of 2014, so I don't (yet) know why I'm having this issue. I may post that later as a separate question. Thanks again!
The uuid.UUID() function is somewhat forgiving when it comes to providing values. See https://docs.python.org/3.5/library/uuid.html. Does the UUID in your JSON data match any of those formats? The only common format for a UUID that I've seen that doesn't match any of those formats would be 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' which is a string that contains dashes, but no surrounding braces. I believe that's the format that is pulled when using UUID's from Django installations by default. I'm actually surprised the Python UUID library doesn't support it, but maybe it's one of those RFC things that specifies the formats that must be accepted.
James,I used csvkit csvkit.readthedocs.org/en/latest/index.html to convert the csv to json.
On Wednesday, February 17, 2016 at 7:05:59 PM UTC-6, James Schneider wrote:The uuid.UUID() function is somewhat forgiving when it comes to providing values. See https://docs.python.org/3.5/library/uuid.html. Does the UUID in your JSON data match any of those formats? The only common format for a UUID that I've seen that doesn't match any of those formats would be 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' which is a string that contains dashes, but no surrounding braces. I believe that's the format that is pulled when using UUID's from Django installations by default. I'm actually surprised the Python UUID library doesn't support it, but maybe it's one of those RFC things that specifies the formats that must be accepted.Okay, THIS really bothers me for a couple of reasons. 1) Yes, my uuids are in the 8-4-4-4-12 format. 2) Yes, this comes from using the uuidfield as recommended in the docs https://docs.djangoproject.com/es/1.9/ref/models/fields/#uuidfield 3) You're right, this 8-4-4-4-12 format IS NOT on the Python docs page you referred me to.
How can Django say this is based on the Python uuid module when it does not comply? What GOOD is it if it does not comply? Now maybe there is some internal workings that hack a valid Python format. My guess
is UUID('urn:uuid:12345678-1234-5678-1234-567812345678'). It wouldn't be that hard to strip off the urn:uuid, and I know for a fact, because I've seen it with my own eyes, there is code to strip out the dashes. But essentially you are saying that my problems are NOT JSON (which I had started to suspect anyway, see http://stackoverflow.com/questions/35463713/badly-formed-hexadecimal-uuid-string-error-in-django-fixture-json-uuid-conversi 2nd Update. But you also seem to be saying this is not a bug, but a 'feature', because Django knows their uuid format does not comply. But that doesn't make sense to me. How is it to be effectively used without universal Python compliance? Why isn't this lack of compliance documented? What is the workaround, or does it just mean junk the Django uuid altogether as not ready for prime time and save yourself days and days of work, like the days I wasted all last week on this thing?!
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXL%3DsE%3DAw7%2BON81RNo1G8cDmQ52Vy%3Dxg_YF1zkiFjQ9pw%40mail.gmail.com.
The only uuid currently in this fixture is the one I got from Django when I put another model (only one row) in with a fixture (no date field) and it worked. I needed the uuid of that object to put into the foreign key of the model I am having trouble with now.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX%3Dz0KEvJJdMF7%3D3MKrWsuvhO6P%2B6%2BRso_QYM4Y6%3D4gsA%40mail.gmail.com.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160219232920.GF880%40koniiiik.org.
I am pursuing the debug option now to see what I can learn.
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Q4zybgExDyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciVUtK1LtfpfsNBRF1chO_wxG_pabr8F3wZRZVR6G0SwqQ%40mail.gmail.com.