Tag: cast

Rails迁移:尝试将列的类型从字符串更改为整数

我在rails应用程序中使用rails generate migrations命令创建了一个表。 这是迁移文件: class CreateListings < ActiveRecord::Migration def change create_table :listings do |t| t.string :name t.string :telephone t.string :latitude t.string :longitude t.timestamps end end end 然后我想将纬度和经度存储为整数,所以我试图运行: rails generate migration changeColumnType 并且该文件的内容是: class ChangeColumnType < ActiveRecord::Migration def up #change latitude columntype from string to integertype change_column :listings, :latitude, :integer change_column :listings, :longitude, :integer #change longitude […]