Django错误:无法将字符串转换为源代码中的float,而不是我自己的cod

2024-04-24 23:31:23 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试运行python manage.py migrate来同步数据库时,我得到了一个错误

File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/Library/Python/2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/Library/Python/2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/Library/Python/2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
    field,
  File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/schema.py", line 179, in add_field
    self._remake_table(model, create_fields=[field])
  File "/Library/Python/2.7/site-packages/django/db/backends/sqlite3/schema.py", line 77, in _remake_table
    self.effective_default(field)
  File "/Library/Python/2.7/site-packages/django/db/backends/base/schema.py", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 710, in get_db_prep_save
    prepared=False)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 702, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 1804, in get_prep_value
    return float(value)
ValueError: could not convert string to float: Jestem watowcem

在模型.py文件:

^{2}$

所以在我自己的代码中,我没有“Jestem watowcem”这样的字符串。我刚把它取下来做测试,但仍然可以看到错误。 python manage.py makemigration <app>运行正常 python manage.py migrate-调用上述错误

错误列表中只有一个文件是可编辑的管理.py但自从项目开始我就没有编辑过。在

所以,如果在我自己的代码中我没有字符串变量,但是Python想告诉我它不能转换值,有人知道我可以做什么或者应该在哪里删除这个变量吗?在


Tags: djangoinpyselfexecutedbvaluepackages