Re: cannot import blank value to IntegerField()

2011-08-04 Thread Jeremy Dunck
On Wed, Aug 3, 2011 at 5:08 PM, Didymus  wrote:
...
> ERROR:  invalid input syntax for integer: ""
> CONTEXT:  COPY train_emp, line 1, column phone: ""
...
> I have tried the following code in models.py
>
> phone  = models.IntegerField(blank=True)
> phone  = models.IntegerField(null=True)
> phone  = models.IntegerField(null=True, blank=True).

blank=True affects only model validation, which is a separate layer
than the database.

null=True allows nulls, but "" is not the same as null (at least in PostgreSQL).

I think this may be a question for the postgres mailing list since
this has little to do with django, but to be helpful, perhaps you are
using the import command incorrectly?  You didn't list the command you
run, but here's a reference:
http://www.postgresql.org/docs/8.2/static/sql-copy.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



cannot import blank value to IntegerField()

2011-08-03 Thread Didymus
Hi,

I am experimenting with Django v1.3 and using a PostgreSQL db.

Having created the model and syncdb the db I next proceed to import
the data from a legacy db via a .csv file via a PostgreSQL command
prompt.

I have checked all the data.  What appears to be happening is that for
an IntegerField() if the column being imported contains no data the
PostgreSQL command prompt reports...

ERROR:  invalid input syntax for integer: ""
CONTEXT:  COPY train_emp, line 1, column phone: ""

The problem does not arise if I put a number into the column in
the .csv file.

I have tried the following code in models.py

phone  = models.IntegerField(blank=True)
phone  = models.IntegerField(null=True)
phone  = models.IntegerField(null=True, blank=True).

These do not work.

Thank you for your help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.