我正在使用 Ruby on Rails,我不再需要我的表 Order
,所以我使用 SQLite 管理器删除了它。我怎样才能在 heroku 中删除表?
编辑 我收到错误
db/migrate/20110806052256_droptableorders.rb:10: syntax error, unexpected keyword_end, expecting $end
当我运行命令时
class DropTableOrder < ActiveRecord::Migration
self.up
drop_table :orders
end
self.down
raise IrreversibleMigration
end
end
最佳答案
如果你不想创建一个迁移来删除表并且不能回滚以前的迁移,因为你不想丢失迁移后创建的表中的数据,你可以在 heroku 控制台上使用以下命令来放下一张 table :
$ heroku console
Ruby console for heroku-project-name
>> ActiveRecord::Migration.drop_table(:orders)
以上命令将从您的 heroku 数据库中删除表。您可以在 ActiveRecord::Migration 模块中使用其他方法,如 create_table、add_column、add_index 等来操作数据库,而无需创建和运行迁移。但请注意,这会在 Rails 创建的用于管理迁移版本的 schema_migrations 表中留下一团糟。
这只有在您的应用程序仍在开发中并且您不想丢失在 heroku 上的远程登台服务器上添加的数据时才有用。
关于ruby-on-rails - Heroku Drop Table Rails 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6964824/