Skip to main content

Got an error while coding in django

 error is in an element name "price" in model.py.

error:    return field.get_db_prep_save(self._effective_default(field), self.conne

ction)

  File "C:\Users\Shubrajit Acharjee\PycharmProjects\untitled\lib\site-packag

es\django\db\models\fields\__init__.py", line 823, in get_db_prep_save

    return self.get_db_prep_value(value, connection=connection, prepared=Fal

se)

  File "C:\Users\Shubrajit Acharjee\PycharmProjects\untitled\lib\site-packag

es\django\db\models\fields\__init__.py", line 818, in get_db_prep_value

    value = self.get_prep_value(value)

  File "C:\Users\Shubrajit Acharjee\PycharmProjects\untitled\lib\site-packag

es\django\db\models\fields\__init__.py", line 1776, in get_prep_value

    raise e.__class__(

ValueError: Field 'price' expected a number but got ''.


solution:Go to migrations file and delete all the auto generated migration files related to element "price" and code correctly in models.py file and run python manage.py makemigrations and migrate commands. Problem solved

source:https://www.reddit.com/r/django/comments/ekuv27/valueerror_field_id_expected_a_number_but_got_on/ 

after solving output:

>python manage.py makemigrations

Migrations for 'shop':

  shop\migrations\0003_auto_20200830_2343.py

    - Add field category to product

    - Add field image to product

    - Add field price to product

    - Add field subcategory to product


(untitled) C:\Users\Shubrajit Acharjee\PycharmProjects\ecomsitedjango\mycart

>python manage.py migrate

Operations to perform:

  Apply all migrations: admin, auth, contenttypes, sessions, shop

Running migrations:

  Applying shop.0003_auto_20200830_2343... OK



Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

Blog #12

Its 6:50PM in the evening. I started Django yesterday, and as expected problem arrived while I'm in PowerShell for preparing Django. However, I solved it using commands like pip install Django & pip install Django --upgrade(tutorial by code with harry youtube videos), and after that error occurred: pip is not recognized and I again download python from its official website and the error was solved hopefully. After that, I created a folder djangoproject and go to vs code terminal and run a command "django-admin startproject <newfoldername>",  but showed me "django-admin startproject hello django-admin : the term 'django-admin' is not recognized as the name of a cmdlet function script file or operable program. check the spelling of the name or if a path was included verify that the path is correct and try again."   Reason of this error is because of the file path/directory in Powershell. Its needs to change.  So my first approach was to go to adm...