首页 > 解决方案 > 无法将类型日期转换为没有时区的时间 LINE 1: ...COLUMN "creation_date" TYPE time USING "creation_date"::time (DJANGO - Heroku)

问题描述

我正在尝试将我的 Django 项目上传到 Heroku。我像往常一样运行以下命令:

git add .
git commit -am ""
git push heroku master
heroku run bash
$- python manage.py migrate //this for apply all the migrations

一旦我运行它们,我就得到了cannot cast type date to time without time zone.

我已经找到了一些答案,但没有一个对我有用。

我已经TIME_ZONE在 settings.py 中设置了

这是给我错误的迁移:

# Generated by Django 3.1.7 on 2021-08-16 16:29

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

    dependencies = [
        ('website', '0009_order_creation_date'),
    ]

    operations = [
        migrations.AlterField(
            model_name='order',
            name='creation_date',
            field=models.TimeField(default=django.utils.timezone.now, verbose_name='Data Ordine'),
        ),
    ]

标签: pythondjangoheroku

解决方案


我只是通过重置数据库来解决它。然后我将 DateTimeField 默认值从 timezone.now 更改为 auto_now_add=True


推荐阅读