Python Can';我不知道如何调试这个:ValueError:invalid literal for int(),以10为基数:';

Python Can';我不知道如何调试这个:ValueError:invalid literal for int(),以10为基数:';,python,django-models,Python,Django Models,我刚刚遇到了这个错误,我试图在论坛上类似错误的帮助下进行调试,但没有任何结果。 我想它来自于我的模型,关于模型字段以及它们是如何返回的。 特别是预订和房间型号下的预订id和房间号。 感谢您的帮助。 注意:我更改了模型字段,每当我运行manage.py migrate时,值错误就会弹出 Models.py class Room(models.Model): Hostel = models.ForeignKey(List) Room_Number = models.CharField

我刚刚遇到了这个错误,我试图在论坛上类似错误的帮助下进行调试,但没有任何结果。 我想它来自于我的模型,关于模型字段以及它们是如何返回的。 特别是预订和房间型号下的预订id和房间号。 感谢您的帮助。 注意:我更改了模型字段,每当我运行manage.py migrate时,值错误就会弹出

Models.py

class Room(models.Model):
    Hostel = models.ForeignKey(List)
    Room_Number = models.CharField(max_length=3, default="", primary_key=True)
    Total_rooms = models.IntegerField(blank=True)
    Price_single = models.IntegerField(blank=True)
    Price_double = models.IntegerField(blank=True)

    def __str__(self):
        return self.Room_Number


class Booking(models.Model):
    Book_id = models.IntegerField(default="")
    Hostel = models.ForeignKey(List)
    Room_Number = models.ForeignKey(Room)
    Room_capacity = models.CharField(max_length=1, choices=[('S', 'Single'), ('D', 'Double')], default="")
    Booked_by = models.ForeignKey(Student, default="")
    Booked_on = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return "%s, booked a '%s' room in '%s' '%s' at '%s'" % (
            self.Booked_by, self.Room_capacity, self.Hostel, self.Room_Number, self.Booked_on)
在控制台中显示:

Running migrations:
  Rendering model states... DONE
  Applying Gyobera.0011_booking_book_id...Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 4.5.2\helpers\pycharm\django_manage.py", line 41, in <module>
    run_module(manage_file, None, '__main__', True)
  File "C:\Python34\lib\runpy.py", line 182, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "C:\Python34\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:/Users/Scott Businge/Ewange\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 390, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 441, in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py", line 221, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "C:\Python34\lib\site-packages\django\db\migrations\executor.py", line 147, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Python34\lib\site-packages\django\db\migrations\migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Python34\lib\site-packages\django\db\migrations\operations\fields.py", line 62, in database_forwards
    field,
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", line 179, in add_field
    self._remake_table(model, create_fields=[field])
  File "C:\Python34\lib\site-packages\django\db\backends\sqlite3\schema.py", line 77, in _remake_table
    self.effective_default(field)
  File "C:\Python34\lib\site-packages\django\db\backends\base\schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 710, in get_db_prep_save
    prepared=False)
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 702, in get_db_prep_value
    value = self.get_prep_value(value)
  File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line 1868, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: ''
运行迁移:
正在渲染模型状态。。。完成
正在应用Gyobera.0011\u预订\u书籍\u id…回溯(最近一次呼叫最后一次):
文件“C:\Program Files(x86)\JetBrains\PyCharm 4.5.2\helpers\PyCharm\django_manage.py”,第41行,在
运行\u模块(管理\u文件,无,'.\u主\u',真)
文件“C:\Python34\lib\runpy.py”,第182行,在run\u模块中
返回\u运行\u模块\u代码(代码、初始化全局、运行\u名称、模块规格)
文件“C:\Python34\lib\runpy.py”,第96行,在运行模块代码中
模块名称、模块规格、组件名称、脚本名称)
文件“C:\Python34\lib\runpy.py”,第85行,在运行代码中
exec(代码、运行\全局)
文件“C:/Users/Scott Businge/Ewange\manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“C:\Python34\lib\site packages\django\core\management\\ uuuu init\uuuu.py”,第338行,从命令行执行
utility.execute()
文件“C:\Python34\lib\site packages\django\core\management\\uuuu init\uuuuu.py”,第330行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“C:\Python34\lib\site packages\django\core\management\base.py”,第390行,运行于\u argv
self.execute(*args,**cmd_选项)
文件“C:\Python34\lib\site packages\django\core\management\base.py”,第441行,在execute中
输出=self.handle(*args,**选项)
文件“C:\Python34\lib\site packages\django\core\management\commands\migrate.py”,第221行,位于句柄中
executor.migrate(目标、计划、假=假、假首字母=假首字母)
文件“C:\Python34\lib\site packages\django\db\migrations\executor.py”,第110行,在migrate中
self.apply\u迁移(状态[迁移],迁移,假=假,假首字母=假首字母)
文件“C:\Python34\lib\site packages\django\db\migrations\executor.py”,第147行,在apply\u migration中
state=migration.apply(状态,模式编辑器)
文件“C:\Python34\lib\site packages\django\db\migrations\migration.py”,第115行,在apply中
操作。数据库转发(self.app\u标签、模式编辑器、旧状态、项目状态)
数据库中第62行的文件“C:\Python34\lib\site packages\django\db\migrations\operations\fields.py”
领域
文件“C:\Python34\lib\site packages\django\db\backends\sqlite3\schema.py”,第179行,在add\u字段中
self.\u重新生成\u表(模型,创建字段=[field])
文件“C:\Python34\lib\site packages\django\db\backends\sqlite3\schema.py”,第77行,在表中
自生效默认值(字段)
文件“C:\Python34\lib\site packages\django\db\backends\base\schema.py”,第211行,默认有效
默认值=field.get\u db\u prep\u save(默认值,self.connection)
文件“C:\Python34\lib\site packages\django\db\models\fields\\ uuuu init\uuuuu.py”,第710行,在get\u db\u prep\u save中
准备就绪(错误)
文件“C:\Python34\lib\site packages\django\db\models\fields\\ uuu init\uuuu.py”,第702行,在get\u db\u prep\u值中
value=self.get\u prep\u值(value)
文件“C:\Python34\lib\site packages\django\db\models\fields\\ uuuuu init\ uuuuuu.py”,第1868行,在get\u prep\u值中
返回int(值)
ValueError:基数为10的int()的文本无效:“”

您的
图书ID
默认为空字符串

Book_id = models.IntegerField(default="")
您可能希望允许空值或将默认值设置为数字

Book_id = models.IntegerField(default=1)

book\u id
的默认值更改为整数值。例如:

Book_id = models.IntegerField(default=0)

(虽然
\u id
有点让我觉得你有一个图书模型,在这种情况下,无论如何它应该是外键。)同样的情况也适用于
预订的
谢谢大家,我已经这样做了,但仍然存在值错误