Wednesday, July 26, 2017

Re: ValueError: invalid literal for int() with base 10:

The problem was I had records in the database from before I changed the 'their_company' field to a ForeignKey. Before it was a CharField so some of the records had actual company names in them. I deleted those records since there wasnt any real data in there anyways, just dummy data. Everything works the way its supposed to now.




On Wednesday, July 26, 2017 at 1:42:26 PM UTC-6, Alexander Joseph wrote:
Hi, thanks for the reply, however when I take out the 'their_company' field altogether everything works fine. Also in the error it references the their_company field. The entire error is  "invalid literal for int() with base 10: 'NewCor'" NewCor is a company in the contacts table. Thanks



On Wednesday, July 26, 2017 at 1:27:28 PM UTC-6, Tim Chase wrote:
On 2017-07-26 11:52, Alexander Joseph wrote:
> "*ValueError: invalid literal for int() with base 10:*" after I
> made a field in my models.py a ForeignKey. Below is my models.py

The problem lies in this line:

>                 new_invoice_num = int(last_invoice_num) + 1

For some reason last_invoice_num is an invalid value to pass to
int().  You'd have to check what that actual value is that you're
passing to the function.  The error message *should* specify what
that value is:

>>> int("x")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'x'
>>> int("")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''

but you seem to have truncated it so it's a little hard to tell from
the error message.  It's not None as that produces a different
message:

>>> int(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string, a bytes-like object or a
number, not 'NoneType'

-tkc



--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/f85e13b0-06a4-42e5-a52a-c27cef9438de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment