【发布时间】:2017-01-06 01:45:10
【问题描述】:
我正在编写一个当前部署在 heroku 上的 django 应用程序。我所做的最新迁移引发了一个我不明白的错误,见下文。 这个错误在本地没有出现,可能是因为我在本地使用了sqlite,在heroku上使用了postgres,但这只是一个猜测。 我在本地生成迁移并推送它。
我使用 django 1.10 和带有 python 2.7 的虚拟环境。
这是我尝试运行迁移时的终端输出:
heroku run python manage.py migrate
Running python manage.py migrate on ⬢ limitless-lake-59470... up, run.3202 (Free)
Operations to perform:
Apply all migrations: admin, auth, contenttypes, jobs, sessions
Running migrations:
Applying jobs.0015_auto_20161230_2039...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 367, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, 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 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 345, 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 204, 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 495, 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 117, in _alter_field
new_db_params, strict,
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 649, in _alter_field
params,
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 112, in execute
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: invalid input syntax for integer: ""
【问题讨论】:
-
"可能是因为我在本地使用 sqlite 并在 heroku 上使用 postgres,但这只是一个猜测。"很可能。 sqlite 不强制类型。 Postgresql 可以。请发布有问题的模式
-
整个models.py文件比较大,不知道是什么原因造成的。无论如何,我通过清除整个数据库并从头开始应用迁移来解决此问题。不知道为什么这会有所帮助,但确实如此。