【发布时间】:2023-03-20 04:35:01
【问题描述】:
我有一个 Rails 3.2 应用程序,它将邮政编码存储在 user_profiles 表中。我最初使用整数作为邮政编码的数据类型;但是,这显然是错误的,因为您不能使用以零开头的数字(并且某些美国邮政编码确实以零开头)。因此,我需要将邮政编码列和我的生产数据转换为字符串。我认为这是通过简单的 change_column 迁移完成的,但我不知道使用 Postgres 时要使用的确切代码。任何帮助将非常感激!我添加邮政编码列的原始迁移如下:
class AddZipCodeToUserProfiles < ActiveRecord::Migration
def change
add_column :user_profiles, :zip_code, :integer
end
end
【问题讨论】: