我正在创建网站数据库。对于其中一列,我使用项目编号代码作为整数。无法处理数字大小,因此最好将其设置为字符串。但我已经将它设置为一个整数,我不能简单地在代码中进行更改。我该怎么做呢?Rails:如何将整数更改为字符串
这是我的迁移文件。
class CreateInventories < ActiveRecord::Migration[5.1]
def change
create_table :inventories do |t|
t.string :product_name
t.string :brand_name
t.integer :item_id
t.integer :upc_code
t.string :color
t.string :department
t.string :size
t.string :condition
t.string :fabric_type
t.string :shipping_weight
t.string :sku
t.string :asin
t.integer :quantity
t.string :cost_price
t.string :sell_price
t.string :key_product_features
t.text :product_description
t.string :search_terms
t.string :status
t.string :listing_in_usa
t.string :listing_in_canada
t.string :listing_in_mexico
t.timestamps
end
end
end
我想使upc_code和item_id都变成字符串。我如何开始?
好了,在新的文件我的代码是
class UpdateColumn < ActiveRecord::Migration[5.1]
def change
change_table :inventories do |t|
t.change :upc_code, :string
end
end
end
,但我得到一个错误
的ActiveRecord :: PendingMigrationError迁移仍在进行中。要解决 此问题,运行:BIN /导轨分贝:迁移RAILS_ENV =发展
此表是正在进行的工作,还是已合并到主/部署在任何地方?除非只存在于本地计算机上,否则很少需要编辑现有的迁移。 –
运行'rails db:migrate'。这就是为什么你得到ActiveRecord :: PendingMigrationError – UsamaMan
这就是我所做的,但我仍然得到一个错误 – Davidson