【发布时间】:2018-03-08 13:52:24
【问题描述】:
我的一个迁移文件消失在蓝天 ????♂️ 我想我需要手动重写它。 ????
这是我在 schema.rb 中为该表提供的内容
+ create_table "collections", force: :cascade do |t|
+ t.string "title"
+ t.string "description"
+ t.bigint "designer_id"
+ t.datetime "created_at", null: false
+ t.datetime "updated_at", null: false
+ t.index ["designer_id"], name: "index_collections_on_designer_id"
+ end
那么我的自定义迁移应该如下所示吗?
def change
create_table :collections do |t|
t.string :title
t.string :description
t.integer :designer_id
t.timestamps
end
end
我应该对 add_index 做些什么吗?
谢谢!
------------
编辑的解决方案想法
我将添加到现有的迁移文件,而不是创建新文件。所以下面的代码应该可以完成这项工作,对吧?
class AddSlugToCollections < ActiveRecord::Migration[5.1]
def change
create_table :collections do |t|
t.string :title
t.string :description
t.integer :designer_id
t.timestamps
end
add_index :collections, :designer_id
add_column :collections, :slug, :string
add_index :collections, :slug
end
end
【问题讨论】:
标签: ruby-on-rails database postgresql migration ruby-on-rails-5