Ask Your Question

Where is the "add_tsvector_column" method pulled from?

asked 2012-12-20 09:09:09 -0500

mrB's avatar

updated 2012-12-20 09:39:37 -0500

I still can't migrate past 0137.

Django 1.3.1
Askbot started with original version 0.7.43 and trying to migrate to Askbot 0.7.47
PostgreSQL 9.1.3

It seems that there is a Postgresql function that is being requested that doesn't exist: add_tsvector_column()

$ python migrate  

Running migrations for longerusername:  
- Nothing to migrate.  
 - Loading initial data for longerusername.  
No fixtures found.  
Running migrations for django_authopenid:  
- Nothing to migrate.  
 - Loading initial data for django_authopenid.  
No fixtures found.  
Running migrations for askbot:  
 - Migrating forwards to 0158_add_title_search_indices_for_postgresql_and_mysql.  
 > askbot:0127_save_category_tree_as_json  
 > askbot:0128_add_groups_field__to__thread_and_post  
 > askbot:0129_auto__del_field_post_is_private  
 > askbot:0130_auto__del_field_postrevision_revision_type  
 > askbot:0131_auto__add_field_tag_status  
 > askbot:0132_auto__add_draftquestion__add_draftanswer  
 > askbot:0133_apply_global_group_to_posts_and_users  
Moving group-less threads to the global group  
------------------------------------------------------------ 100.00%  
Added global group to 17 threads.  

Move groupless questions and answers to the global group  
------------------------------------------------------------ 100.00%  
Added global group to 19 posts.  

Adding all users to the global group  
------------------------------------------------------------ 100.00%  
Added global group to 3 users.  
 > askbot:0134_create_personal_groups_for_all_users  
Creating personal group for the users  
------------------------------------------------------------ 100.00%  
 > askbot:0135_auto__add_questionwidget__add_askwidget  
 > askbot:0136_auto__add_group__add_threadtogroup__add_unique_threadtogroup_thread_ta  
 > askbot:0137_create_groups_from_relevant_tags  
Transfering group information from Tag to Group model  
------------------------------------------------------------ 100.00%  
Deleting old group information  
------------------------------------------------------------ 100.00%  
The following content types are stale and need to be deleted:  

    askbot | groupprofile  

Any objects related to these content types by a foreign key will also  
be deleted. Are you sure you want to delete these content types?  
If you're unsure, answer 'no'.  

    Type 'yes' to continue, or 'no' to cancel: yes  
Traceback (most recent call last):  
  File "", line 11, in <module>  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/", line 438, in execute_manager  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/", line 379, in execute  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/", line 191, in run_from_argv  
    self.execute(*args, **options.__dict__)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/", line 220, in execute  
    output = self.handle(*args, **options)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/management/commands/", line 105, in handle  
    ignore_ghosts = ignore_ghosts,  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/", line 191, in migrate_app  
    success = migrator.migrate_many(target, workplan, database)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/", line 221, in migrate_many  
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/", line 292, in migrate_many  
    result = self.migrate(migration, database)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/", line 125, in migrate  
    result =  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/", line 99, in run  
    return ...
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-12-20 15:42:09 -0500

mrB's avatar

I'm not sure if this was the correct way of fixing this problem. After reading a little bit about PostgreSQL functions, I decided to add the functions directly to the file:

After the addition, the migration ran successfully.

    /* function testing for existence of a column in a table
   if table does not exists, function will return "false" */
CREATE OR REPLACE FUNCTION column_exists(colname text, tablename text)
RETURNS boolean AS 
    q text;
    onerow record;

    q = 'SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT oid FROM pg_class WHERE relname = '''||tablename||''') AND attname = '''||colname||''''; 

    FOR onerow IN EXECUTE q LOOP
        RETURN true;

    RETURN false;
$$ LANGUAGE plpgsql;

/* function adding tsvector column to table if it does not exists */
CREATE OR REPLACE FUNCTION add_tsvector_column(colname text, tablename text)
RETURNS boolean AS
    q text;
    IF NOT column_exists(colname, tablename) THEN
        q = 'ALTER TABLE ' || tablename || ' ADD COLUMN ' || colname || ' tsvector';
        EXECUTE q;
        RETURN true;
        q = 'UPDATE ' || tablename || ' SET ' || colname || '=NULL';
        EXECUTE q;
        RETURN false;
    END IF;
$$ LANGUAGE plpgsql;
edit flag offensive delete link more


This function exists for example, in thread_and_post_models_05222012.plsql, which is supposed to be run in earlier migrations. Maybe you did not run it or lost the function somehow?

Evgeny's avatar Evgeny  ( 2012-12-21 19:25:11 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-12-20 09:09:09 -0500

Seen: 2,659 times

Last updated: Dec 20 '12