Thanks for pointing me in the right direction.
I added a simple
try:
y = float(row[6])
except:
y = None
And changed the area_hectares=y, in my script.
Everything works fine now.
Best
> On 16 Oct 2019, at 12:20, Kasper Laudrup <[email protected]> wrote:
>
> Hi again,
>
> On 16/10/2019 13.02, 'David Turner' via Django users wrote:
>> Thanks for your response
>
> You're welcome.
>
>> I am using djjango-extensions to run the script. Everything imports fine
>> except the one field. The Category, Region, County and Iso’s are foreign
>> keys to the property.
>> The data in the csv for the area_hectares does contain in some cases no data
>> but the format for the data is:
>> 158.9265
>> 70
>> 58.9
>> 150
>> 7200000
>> 665.03
>
> Since no data is represented as an empty string you need to special case
> handle that so that gets converted to a NoneType instead.
>
> Instead of simply calling float(row[6]) in your import script (which will
> raise the ValueError exception on empty strings) a solution could be to write
> a small wrapper function that tests if the input argument is an empty string
> and returns None in that case, otherwise calls the float type converter as
> usual.
>
> That function should be trivial to write, but that's not the only solution of
> course.
>
> Thinking about, I'm not 100% sure that a nullable field in Django can be
> created with a NoneType (that will then set the type to Null), but I'm fairly
> certain. Someone please correct me if I'm wrong.
>
> Kind regards,
>
> Kasper Laudrup
>
> --
> 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/vlHtz3JtsC0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a7420722-8818-4c89-3eb7-4224c70dfc9d%40stacktrace.dk.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/1DE20C20-E9F5-4731-A1E1-4FBF787322CE%40googlemail.com.