I created a models in django-framework but after run migrate, I got this type of error
from django.db import models
# Create your models here.
class Product(models.Model):
product_id = models.AutoField
product_name = models.CharField(max_length=50)
category = models.CharField(max_length=50, default="")
subcategory = models.CharField(max_length=50, default="")
price = models.IntegerField(default=0)
image = models.ImageField(upload_to="shop/images", default="")
desc = models.CharField(max_length=300)
pub_date = models.DateField()
def __str__(self):
return self.product_name
but I get this error after run migrate PS C:\Users\Lenovo\Desktop\django-recap\django\myshopcart> python manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, shop Running migrations: Applying shop.0002_auto_20201208_0348...Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields_init_.py", line 1774, in get_prep_value return int(value) ValueError: invalid literal for int() with base 10: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Lenovo\Desktop\django-recap\django\myshopcart\manage.py", line 22, in <module>
main()
File "C:\Users\Lenovo\Desktop\django-recap\django\myshopcart\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\base.py", line 85, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\core\management\commands\migrate.py", line 243, in handle
post_migrate_state = executor.migrate(
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\executor.py", line 227, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\migrations\operations\fields.py", line 104, in database_forwards
schema_editor.add_field(
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\schema.py", line 328, in add_field
self._remake_table(model, create_field=field)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\schema.py", line 189, in _remake_table
self.effective_default(create_field)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\backends\base\schema.py", line 303, in effective_default
return field.get_db_prep_save(self._effective_default(field), self.connection)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 823, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 818, in get_db_prep_value
value = self.get_prep_value(value)
File "C:\Users\Lenovo\AppData\Roaming\Python\Python39\site-packages\django\db\models\fields\__init__.py", line 1776, in get_prep_value
raise e.__class__(
ValueError: Field 'price' expected a number but got ''.