无法回滚迁移.标准错误:发生错误,所有后续迁移均已取消



我刚刚迁移了一个文件,但在 def down中我忘记以相反的顺序放置列。 迁移后更新了架构,但我无法回滚。我尝试反转迁移文件中的列顺序。

class AddAttachmentPictureToHotels < ActiveRecord::Migration[5.2]
def self.up
change_table :hotels do |t|
t.attachment :picture
t.float :latitude
t.float :longitude
t.float :distance
end
end
def self.down
remove_attachment :hotels, :picture
remove_float :hotels, :latitude
remove_float :hotels, :longitude
remove_float :hotels, :distance
end
end

我的架构是这个

create_table "hotels", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "city_id"
t.string "picture_file_name"
t.string "picture_content_type"
t.integer "picture_file_size"
t.datetime "picture_updated_at"
t.float "lattitude"
t.float "longitude"
t.float "distance"
t.index ["city_id"], name: "index_hotels_on_city_id"
end

如何回滚?

将其更改为此

def self.down
remove_column :hotels, :picture
remove_column :hotels, :lattitude
remove_column :hotels, :longitude
remove_column :hotels, :distance
remove_column :hotels, :picture_file_name
remove_column :hotels, :picture_content_type
end

附带说明一下lattitude拼写错误,应该latitude

最新更新