Skip to content
Advertisement

PostgreSQL with SQLAlchemy won’t allow empty entries

I have spent a lot of time trying to figure this one out but just cannot seem to find anything. I want to allow empty entries in my database since not all fields are necessary and what is necessary will change depending on the input. I thought nullable entries could be empty…

This is the error I get out. Note that the values are just some dummy values I put in and have no significance. In the list of VALUES in the error, there is a little carrot pointing to the empty ” after ‘133’ as the issue:

(psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type real: “” LINE 1: …mit_date) VALUES (‘3645’, ‘654’, ‘Change’, ‘133’, ”, ‘0’, ‘…

Here is the code I have:

The Flask+SQLAlchemy:

And here is what PGAdmin says the code for the table is:

It seems like the fields I specified as nullable should allow for no entry, but when I try it fails. I only works when I fill in all fields. What am I doing wrong? Also, if anyone sees any really stupid formatting on my part (this is my first attempt at database stuff), let me know and I’ll fix it.

Advertisement

Answer

The problem actually appears to be that you are trying to insert a value of type String (Varchar) into a field of type Float (Real)

Try this:

or this:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement