Ruby on rails Rails,Postgres-将列类型从整数更改为字符串

Ruby on rails Rails,Postgres-将列类型从整数更改为字符串,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我有一个Rails 3.2应用程序,它在用户配置文件表中存储邮政编码。我最初使用integer作为邮政编码的数据类型;然而,这显然是错误的,因为您不能使用以零开头的数字(而一些美国邮政编码确实以零开头)。因此,我需要将邮政编码列和生产数据转换为字符串。我认为这是通过简单的更改列迁移完成的,但我不知道使用Postgres时要使用的确切代码。任何帮助都将不胜感激!我最初添加邮政编码列的迁移如下: class AddZipCodeToUserProfiles < ActiveRecord::Mi

我有一个Rails 3.2应用程序,它在用户配置文件表中存储邮政编码。我最初使用integer作为邮政编码的数据类型;然而,这显然是错误的,因为您不能使用以零开头的数字(而一些美国邮政编码确实以零开头)。因此,我需要将邮政编码列和生产数据转换为字符串。我认为这是通过简单的更改列迁移完成的,但我不知道使用Postgres时要使用的确切代码。任何帮助都将不胜感激!我最初添加邮政编码列的迁移如下:

class AddZipCodeToUserProfiles < ActiveRecord::Migration
  def change
    add_column :user_profiles, :zip_code, :integer
  end
end
class AddZipCodeToUserProfiles
类变更zipCodeToString

你试过了吗?

谢谢你,约书亚。佩林!工作得很好。我期待着来自Postgres的某种错误消息,但它没有出错。干杯
class ChangeZipCodeToString < ActiveRecord::Migration
  def change
    change_column :user_profiles, :zip_code, :string
  end
end