Problem migrating field type from 'string' to 'text' (postgresql)

73 views
Skip to first unread message

Ian W. Scott

unread,
Jan 7, 2015, 1:49:29 PM1/7/15
to web...@googlegroups.com
I need to migrate an existing database field from (the implicit default) 'string' to 'text'. Since all of the existing data will satisfy the new field contstraints (no 'string' will be ruled out as 'text') I just changed the field type in the model field definition. 

Old:
    Field('response1'),
New:
    Field('response1', 'text'),

Everything seemed to go fine until I tried creating a new record with a long string in that field. I got the following error: 

<class 'psycopg2.DataError'>(value too long for type character varying(512) ).

It looks to me like my postgresql database hasn't actually changed the data type for that column. I thought this would be taken care of by the DAL migration. So how can I change the actual postgre column data type? Or did I do something wrong in the migration?

Massimo Di Pierro

unread,
Jan 7, 2015, 2:22:57 PM1/7/15
to web...@googlegroups.com
which web2py version/date?

Ian W. Scott

unread,
Jan 7, 2015, 2:42:52 PM1/7/15
to web...@googlegroups.com
2.8.2-stable+timestamp.2013.11.28.13.54.07
(Running on Apache/2.2.17 (Unix) mod_wsgi/3.3 Python/2.7.8)

Massimo Di Pierro

unread,
Jan 8, 2015, 11:47:54 PM1/8/15
to web...@googlegroups.com
Please upgrade. This should have worked with that version but this is so old. Hard to day what the problem is.

Ian W. Scott

unread,
Jan 9, 2015, 1:38:08 PM1/9/15
to web...@googlegroups.com
OK, I'm upgrading. Ran into a snag with my passwords file and finding the right port number, but when it's upgraded I'll see whether it does the migration correctly.

Thanks

Paolo Valleri

unread,
Jan 9, 2015, 4:23:27 PM1/9/15
to web...@googlegroups.com
Hi,
I've checked and web2py trunk works as expected (both directions namely string to text and viceversa)
@scott, have you enabled migration? ( DAL(db_uri, migrate=True))

Paolo

Ian W. Scott

unread,
Jan 12, 2015, 11:17:51 AM1/12/15
to web...@googlegroups.com
Thanks Paolo. That was it. I forgot that I had set migrate to False. I really feel foolish, but thanks for pointing me in the right direction.

Ian
Reply all
Reply to author
Forward
0 new messages