0
在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: '-'
您是否在本地使用與heroku相同的數據庫? –
是的我使用相同的數據庫 –
我最好的猜測是,當你在本地運行時,默認值是別的東西,無論是在makemigrations期間用戶輸入還是文件不同。 ValueError有效,如果DBMS相同,則應在同一遷移文件上本地提出。 –