Heroku Django ValueError:无效文字为int()以10为底:' - '
问题描述:
在Heroku上运行迁移时,我总是收到ValueError
。 我的django应用程序在本地没有问题。从我所能看到的情况来看,我认为问题出在这个模型上,但我找不到它会是什么。特别是因为运行makemigrations
并迁移本地工作就好了。Heroku Django ValueError:无效文字为int()以10为底:' - '
的错误,我得到:(注:仅在Heroku上运行时:heroku run 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: '-'
答
我改变0012_auto_20170808_1312.py文件,有行时整数提交了默认为 “ - ”。我删了它。但我仍然不知道为什么在当地这不是问题?
您是否在本地使用与heroku相同的数据库? –
是的我使用相同的数据库 –
我最好的猜测是,当你在本地运行时,默认值是别的东西,无论是在makemigrations期间用户输入还是文件不同。 ValueError有效,如果DBMS相同,则应在同一迁移文件上本地提出。 –