Heroku Django ValueError:基数为10的int()的无效文字:' - '

时间:2022-05-17 22:33:17

I keep getting ValueError when running migrate on Heroku. My django application works with no problems locally. From what I can see I think the problem is with this model, but I can't find what it could be. Specially because running makemigrations and migrate locally works just fine.

在Heroku上运行迁移时,我一直收到ValueError。我的django应用程序在本地没有问题。从我所看到的,我认为问题在于这个模型,但我找不到它可能是什么。特别是因为运行makemigrations并在本地迁移工作正常。

The error I get: (note: only on heroku when running: heroku run python manage.py migrate)

我得到的错误:(注意:运行时仅在heroku上运行:heroku运行python manage.py migrate)

Running python manage.py migrate on ⬢ nameless-sands-... up, run.1867 (Free)
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, narocilnice, sessions
Running migrations:
  Applying narocilnice.0012_auto_20170808_1312...Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/migration.py", line 129, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 215, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 515, in alter_field
    old_db_params, new_db_params, strict)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql/schema.py", line 112, in _alter_field
    new_db_params, strict,
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 613, in _alter_field
    new_default = self.effective_default(new_field)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 229, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 770, in get_db_prep_save
    prepared=False)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 762, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1853, in get_prep_value
    return int(value)
ValueError: invalid literal for int() with base 10: '-'

1 个解决方案

#1


0  

I changed 0012_auto_20170808_1312.py file, there was line when integer filed had default = "-". I deleted it. But I still don't know why locally this was not a problem?

我更改了0012_auto_20170808_1312.py文件,当整数字段的默认值为“ - ”时有行。我删了它。但我还是不知道为什么本地这不是问题?

#1


0  

I changed 0012_auto_20170808_1312.py file, there was line when integer filed had default = "-". I deleted it. But I still don't know why locally this was not a problem?

我更改了0012_auto_20170808_1312.py文件,当整数字段的默认值为“ - ”时有行。我删了它。但我还是不知道为什么本地这不是问题?