First time here? Check out the FAQ!
0

Where is the "add_tsvector_column" method pulled from?

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 manage.py 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 "manage.py", line 11, in <module>  
    execute_manager(settings)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager  
    utility.execute()  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute  
    self.fetch_command(subcommand).run_from_argv(self.argv)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", 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/base.py", 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/migrate.py", line 105, in handle  
    ignore_ghosts = ignore_ghosts,  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/__init__.py", 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/migrators.py", 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/migrators.py", 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/migrators.py", line 125, in migrate  
    result = self.run(migration)  
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/south/migration/migrators.py", line 99, in run  
    return ...
(more)
mrB's avatar
51
mrB
asked 2012-12-20 09:09:09 -0500, updated 2012-12-20 09:39:37 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

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:
user_profile_search_083112012.plsql

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 
$$
DECLARE
    q text;
    onerow record;
BEGIN

    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;
    END LOOP;

    RETURN false;
END;
$$ 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
$$
DECLARE
    q text;
BEGIN
    IF NOT column_exists(colname, tablename) THEN
        q = 'ALTER TABLE ' || tablename || ' ADD COLUMN ' || colname || ' tsvector';
        EXECUTE q;
        RETURN true;
    ELSE
        q = 'UPDATE ' || tablename || ' SET ' || colname || '=NULL';
        EXECUTE q;
        RETURN false;
    END IF;
END;
$$ LANGUAGE plpgsql;
mrB's avatar
51
mrB
answered 2012-12-20 15:42:09 -0500
edit flag offensive 0 remove flag delete link

Comments

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
add a comment see more comments