我在模型上编辑了两个字段并将它们从IntegerField
s 更改为TimeField
s:
class Model(models.Model):
start_time = models.TimeField()
end_time = models.TimeField()
我使用这两个字段来节省天真的时间,这与任何地理时间概念无关,因此没有真正的“时区”(想想类似于比赛时间的东西)。我的本地数据库是 PostgreSQL。
但是,此更改生成的南迁移失败并出现以下错误:
> main:0005_auto__chg_field_model_start_time__chg_field_model_end_time
FATAL ERROR - The following SQL query failed: ALTER TABLE "main_model" ALTER COLUMN "start_time" TYPE time, ALTER COLUMN "start_time" SET NOT NULL, ALTER COLUMN "start_time" DROP DEFAULT;
...
File ".../lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError: column "start_time" cannot be cast to type time without time zone
失败的迁移有这个:
class Migration(SchemaMigration):
def forwards(self, orm):
# Changing field 'Model.start_time'
db.alter_column('main_model', 'start_time', self.gf('django.db.models.fields.TimeField')())
# Changing field 'Model.end_time'
db.alter_column('main_model', 'end_time', self.gf('django.db.models.fields.TimeField')())
关于如何让 postgres 对这种迁移感到满意的任何想法?
PS我正在开发中,所以我真的不关心任何数据迁移。您可以假设数据库是空的。