title: How to use Django's DurationField with Postgres, when defined previously using sqlite?
body: <p>I recently moved all my data from <code>sqlite</code> to <code>postgres</code>. All fields seem to work fine except for the <code>duration</code> field. It is shown as an integer in the admin panel and it does not let me edit or save.</p>
  <p>It works fine with sqlite. However after moving to Postgres, I get the following errors (upon saving or updating):</p>
  <blockquote>
  <p>ProgrammingError at /admin/content/movie/add/</p>
  </blockquote>
  <blockquote>
  <p>column &quot;duration&quot; is of type bigint but expression is of type interval</p>
  </blockquote>
  <blockquote>
  <p>HINT:  You will need to rewrite or cast the expression.</p>
  </blockquote>
  <pre class="lang-py prettyprint-override"><code>class Movie(models.Model):
      &quot;&quot;&quot;
      Stores movie related information.
      &quot;&quot;&quot;
      unique_id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
      name = models.CharField(verbose_name='name', max_length=100, blank=False, unique=True)
      slug = models.SlugField(verbose_name='slug', null=True, blank=True)
      description = models.TextField(verbose_name='description', blank=True)
      poster = models.ImageField(verbose_name='poster',upload_to='posters/movies', default='defaults/video.webp', validators=[validate_image])
      # Field of interest
      duration = models.DurationField(verbose_name='duration')
      created_at = models.DateTimeField(verbose_name='created_at', auto_now_add=True)
  </code></pre>
  <p>I also used the following <code>length</code> method for successfully converting the field to human readable form (when using sqlite), but it does not work after moving to postgres. It says:</p>
  <blockquote>
  <p>duration (int) does not have 'days' attribute</p>
  </blockquote>
  <pre class="lang-py prettyprint-override"><code>def length(self):
          &quot;&quot;&quot;
          Converts timedelta into hours and minutes.
          &quot;&quot;&quot;
          days, seconds = self.duration.days, self.duration.seconds
          hours = days * 24 + seconds // 3600
          minutes = (seconds % 3600) // 60
          seconds = (seconds % 60)
  
          if hours == 0:
              length = f'{minutes} min'
          else:
              if minutes == 0:
                  length = f'{hours} h'
              else:
                  length = f'{hours} h {minutes} min'
          return length
  </code></pre>
  <blockquote>
  <p>Note: I used <code>pgloader</code> to load the sqlite data. <a href="https://pgloader.readthedocs.io/en/latest/quickstart.html#migrating-from-sqlite" rel="nofollow noreferrer">https://pgloader.readthedocs.io/en/latest/quickstart.html#migrating-from-sqlite</a></p>
  </blockquote>