【问题标题】:Remove Tables from Schema从架构中删除表
【发布时间】:2015-08-08 19:45:06
【问题描述】:

这可能是一个相当基本的问题,但我不知道如何在安装我决定不使用的 gem 后进行清理。在Attachinary 的安装过程中,安装说明说要运行rake attachinary:install:migrations - 在我的架构中创建一个新表和索引,在此注明:

create_table "attachinary_files", force: :cascade do |t|
    t.integer  "attachinariable_id"
    t.string   "attachinariable_type"
    t.string   "scope"
    t.string   "public_id"
    t.string   "version"
    t.integer  "width"
    t.integer  "height"
    t.string   "format"
    t.string   "resource_type"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

add_index "attachinary_files", ["attachinariable_type", "attachinariable_id", "scope"], name: "by_scoped_parent", using: :btree

后来我决定使用更简单的附件 gem,并尝试清理并删除附件安装期间创建的所有“东西”。

关于如何清理数据库的任何建议?如果这有什么不同,我正在运行 Postgresql。

【问题讨论】:

    标签: ruby-on-rails database gem rails-migrations


    【解决方案1】:

    创建迁移:

    bundle exec rails g migration remove_attachinary
    

    然后告诉 Rails 做什么:

    def up
      drop_table :attachinary_files
    end
    

    删除默认存在的change方法

    如果您希望此迁移是可逆的,请将您之前的代码复制到 down 方法中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-05
      • 2021-10-29
      • 2019-08-16
      • 2014-08-23
      • 1970-01-01
      • 2015-05-14
      • 1970-01-01
      相关资源
      最近更新 更多