Search code examples
pythondjangoheroku

cannot cast type date to time without time zone LINE 1: ...COLUMN "creation_date" TYPE time USING "creation_date"::time (DJANGO - Heroku)


I am trying to upload my Django-project to Heroku. I run the following command like i have always done:

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

Once i ran them i got the cannot cast type date to time without time zone.

I have already found some answers but none of them works for me.

I have already set the TIME_ZONE in settings.py

This is the migration that gives me the error:

# 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'),
        ),
    ]


Solution

  • I solved it just with a database reset. Then i changed the DateTimeField default value from timezone.now to auto_now_add=True