2014-05-16 33 views
1

我有这个作为迁移:Rails不会运行这个PostgreSQL迁移,为什么?

def up 
    connection.execute(%q{ 
    alter table enterprise_members 
    alter column sso_id 
    type string using cast(sso_id as string) 
    }) 
end 

在哪里我只是想整数转换成字符串。但是当它运行时,它会返回:

PG::UndefinedObject: ERROR: type "string" does not exist 
: 
     alter table enterprise_members 
     alter column sso_id 
     type string using cast(sso_id as string) 

是因为我在试图施放它吗?我该如何解决?

+1

varchar,char,text是数据库类型,“string”不是。字符数据类型可以在[手册]上找到(http://www.postgresql.org/docs/9.3/static/datatype-character.html) –

回答

4

您可以拨打string当您使用Rails的,但如果你选择去手工的方式,因为你在你的片段一样,你必须坚持你的DBMS' datatypes

这带来了另一点:尽量DB-agnostic当你可以!

+0

显然,我无法用另一种方式施放,我必须写下它手册。 – Trip

相关问题