ValueError: Field 'id' expected a number but got 'Processing'

Question:

I’m going to deploy my django application on DigitalOcean. Everything gone well, except following error, and my question is: where can I find source of this error, actually in which file ?

Operations to perform:
  Apply all migrations: admin, auth, ccapp, contenttypes, sessions
Running migrations:
  Applying ccapp.0009_auto_20191207_2148...Traceback (most recent call last):
  File "/home/progbash/ccproject/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1768, in get_prep_value
    return int(value)

ValueError: invalid literal for int() with base 10: 'Processing'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/progbash/ccproject/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/progbash/ccproject/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
...
  File "/home/progbash/ccproject/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 2361, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/home/progbash/ccproject/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1772, in get_prep_value
    ) from e
ValueError: Field 'id' expected a number but got 'Processing'.

models.py:

from datetime import datetime

# Create your models here.
class Question(models.Model):
    question_text = models.TextField(max_length=200)
    answer = models.TextField(max_length=200)

    def __str__(self):
        return self.question_text

class ApplicantStatus(models.Model):
    class Meta:
        verbose_name_plural = "Applicant Statuses"

    name = models.CharField(max_length=30)

    def __str__(self):
        return self.name

class Applicant(models.Model):
    name = models.CharField(max_length=20)
    surname = models.CharField(max_length=30)
    birth_date = models.DateField(blank=False)
    phone = models.CharField(max_length=15)
    email = models.EmailField(max_length=40)
    motivation_letter = models.TextField(max_length=200)
    status = models.ForeignKey(ApplicantStatus, on_delete=models.CASCADE, default=3)
    photo = models.FileField(upload_to='static/applicant_photos', blank=True)

    def __str__(self):
        return self.name


class Message(models.Model):
    message_text = models.CharField(max_length=200)
    sender_name = models.CharField(max_length=30)
    sender_email = models.EmailField(max_length=50)

    def __str__(self):
        return self.sender_name
Asked By: srvqaqa

||

Answers:

The problem was in migration files. I just opened and changed default value from string type to integer.

Answered By: srvqaqa

Just delete all the migration files except the init python file the run python manage.py makemigrations then python manage.py migrate

Answered By: Utibe

I had the same problem with simple CBV like TemplateView or ListView which does not require mandatory parameter. I’m pretty sure the issue comes from the url interpretation. For a simple ListView like

class ProfileList(generic.ListView):
    model = get_user_model()

The url

path('profile_list/dummy', ProfileList.as_view(), name='profile_lv'),

works, whereas the one below, doesn’t, the error: Field ‘id’ expected a number but got ‘profile_lv’ is thrown. Where profile_lv is the name of the url…

path('profile_list', ProfileList.as_view(), name='profile_lv'),

The addition of anything with a slash(/) after the path works?!…

Answered By: openHBP

Just do nothing There are two ways :
1)Delete Your all migrations and type in your terminal:python3 manage.py makemigrations <app_name> then python3 manage.py migrate and then runserver.

2)Just opened and changed default value from string type to integer.

In my opinion choose first option because it is safe way.

Thanks

Answered By: Proud

Just to share the solution that worked with my similar error that been received:
In my case, this same error was received because I was creating the model instant with the fields values directly, without specifying the field name, so always the ID was taking the first one as default (ID=field1).
The problem solved by adding the attributes name as well to the Instant creation.

Was:

model_instant = YourModel(field1, field2,...etc)

Solved by:

model_instant = YourModel(field1 = field1, field2 = field2,...etc)

Do this then follow what been recommended above of 1) deleting the dB file, and 2) delete the migrations then 3) do the makemigrations your_app_name then 4) migrations, then 5) run the server and you should be good to go.

Answered By: HassanSh__3571619

Please Delete your recentally created migrations file then run python manage.py makemigrations and python manage.py migrate. I think your problem going to solve.Please try it now.

Answered By: Rahul Rai

Go to migration files and find the name id is where generate, then just replace id with processor or other name or remove it as it define as verbose_name.

`python manage.py makemigrations`
`python manage.py migrate`
`python manage.py runserver`
Answered By: Parag Kulkarni

Unfortunately, I was faced with this problem, but I was forced to create a new Django project from first, to solve this problem. And it was not solved by just deleting migrations files.

Answered By: Aylin Naebzadeh

I have confronted with similar type of error. My original URL was this one:

v1/unit/

Cleaning the migration files didn’t help me. Fortunately, It just started to work after extending the URL with an additional string:

v1/unit/addProduct/
Answered By: Zekarias Taye Hirpo

I solved it by deleting the db, migrations and pycache files then run migrations & migrate again.

Answered By: mutabazigakuba

From the migration files, we can find the file starting with (001_initial.py,002_auto.py,003_,004_). In those files replace the default value empty string (default= ”) or django.utils.timezone.now() into integer like (default=1). It might solve the problem.enter image description here

Answered By: Yabesh

I got this error when I never added created to the get_or_create

someVariable = "someVariable"

# This will give the error "ValueError: Field 'id' expected a number but got someVariable"

my_model = myModel.objects.get_or_create(someField=someVariable)

It got solved when adding this

# added created

my_model, created = myModel.objects.get_or_create(someField=someVariable)

See this https://docs.djangoproject.com/en/4.0/ref/models/querysets/#get-or-create

Answered By: AnonymousUser

I was getting a similar error and finally found the cause. Just sharing here in case someone made a similar mistake.

I had defined a custom __init__ method on my model and had by mistake only written one * when passing kwargs to super:

def __init__(self, *args, **kwargs):
    super().init(*args, *kwargs)

This resulted in the error message:

ValueError: Field 'id' expected a number but got 'account'.

account was the first keyword argument I was passing when creating a new instance in a view.
In hindsight, the error message makes sense, but it took me an hour of confused debugging before I noticed my typo.

Answered By: Azer

You can do the following:

  1. Clean up your dbase by deleting entries which do not confirm to your model, or putting in values for missing/wrong entries

  2. Make sure values in models are blank=False, null=False and defaults given and then rerun the migration

  3. Put a condition such as if Table.field != "": or whatever value is causing problem in your serializers

Answered By: DragonFire
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.