Opened 9 years ago

Closed 9 years ago

#26053 closed Bug (worksforme)

makemigrations generates a wrong type for a DurationField column on postgresql

Reported by: Benjelloun Mohamed Ayoub Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords: makemigrations, DurationField, postgresql, psycopg2
Cc: benjellounayoub@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Dependencies:

  • Django version : 1.9.1
  • PostgreSQL version : "PostgreSQL 9.4.4 on x86_64-unknown-linux-gnu, compiled by gcc (Ubuntu 4.9.1-16ubuntu6) 4.9.1, 64-bit"
  • DB conf :
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': 'test',
            'USER': 'test',
            'PASSWORD': 'test',
            'HOST': 'localhost',
            'PORT': '',
        },
    }
    

Following those steps:
1 - creating a minimal model example including a DurationField

class Foo(models.Model):
    bar = models.DurationField()

2 - migrate the new model

$ python manage.py makemigrations AppName
$ python manage.py migrate

3 - then check the type of the 'bar' DB column related to the 'bar' DurationField on the 'appname_foo' generated table

\d appname_foo

=> The datatype associated to the bar column is not interval as expected but float

Change History (9)

comment:1 by Simon Charette, 9 years ago

Hi benjellounayoub,

I couldn't reproduce against PostgreSQL 9.3 and 9.3 on Ubuntu with Django 1.9.1 and master using a similar test application.

\d ticket_26053_foo;
                          Table "public.ticket_26053_foo"
 Column |   Type   |                           Modifiers                           
--------+----------+---------------------------------------------------------------
 id     | integer  | not null default nextval('ticket_26053_foo_id_seq'::regclass)
 bar    | interval | not null
Indexes:
    "ticket_26053_foo_pkey" PRIMARY KEY, btree (id)

Can you confirm the generated migration's CreateModel operation used a models.DurationField() for its 'bar' field?

comment:2 by Benjelloun Mohamed Ayoub, 9 years ago

No, unfortunately it's not the case

For the following model

class Foo(models.Model):
    bar = models.DurationField()

I have the following CreateModel in the generated migrations

...
    operations = [
        migrations.CreateModel(
            name='Foo',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('bar', models.FloatField(blank=True, default=0, null=True)),
            ],
...

Can you test it with the 9.4 postgreSQL version instead of the 9.3 ? it's maybe related to this part ...

comment:3 by Tim Graham, 9 years ago

Resolution: worksforme
Status: newclosed

Can you double check you didn't make a mistake (i.e. delete the migration and re-run makemigrations)? It's unthinkable to me that Django would transform DurationField() to FloatField(blank=True, default=0, null=True)).

comment:4 by Benjelloun Mohamed Ayoub, 9 years ago

Sorry but there is no mistake at all, i can reproduce the issue again and again

comment:5 by Benjelloun Mohamed Ayoub, 9 years ago

Resolution: worksforme
Status: closednew

in reply to:  1 comment:6 by Benjelloun Mohamed Ayoub, 9 years ago

Replying to charettes:

I think you are using the Django's version 1.10.dev for your test and not the 1.9

...
# Generated by Django 1.10.dev20160107050803 on 2016-01-07 16:03
...

Hi benjellounayoub,

I couldn't reproduce against PostgreSQL 9.3 and 9.3 on Ubuntu with Django 1.9.1 and master using a similar test application.

\d ticket_26053_foo;
                          Table "public.ticket_26053_foo"
 Column |   Type   |                           Modifiers                           
--------+----------+---------------------------------------------------------------
 id     | integer  | not null default nextval('ticket_26053_foo_id_seq'::regclass)
 bar    | interval | not null
Indexes:
    "ticket_26053_foo_pkey" PRIMARY KEY, btree (id)

Can you confirm the generated migration's CreateModel operation used a models.DurationField() for its 'bar' field?

Version 1, edited 9 years ago by Benjelloun Mohamed Ayoub (previous) (next) (diff)

comment:7 by Tim Graham, 9 years ago

Could you please provide a sample project with steps to reproduce it? For the provided model, I'm still seeing this for the 1.9 branch:

migrations.CreateModel(
    name='Foo',
    fields=[
        ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
        ('bar', models.DurationField()),
    ],
),

comment:8 by Simon Charette, 9 years ago

@benjellounayoub, the migration I commited was generated with the master branch because I first reproduced against 1.9 and tried against master to see if it was fixed.

I managed to reproduce against Django again. Please let me know if I missed something.

Are you sure you don't have any third party app that might have interfered and you are really using the django.db.models.DurationField?

comment:9 by Tim Graham, 9 years ago

Resolution: worksforme
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top