我正在使用Ruby on Rails,我不再需要我的表Order
所以我使用SQLite管理器删除了它。如何在heroku中删除表?
EDIT 我收到了错误
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
答案 0 :(得分:21)
如果您不想创建迁移到删除表并且无法回滚以前的迁移,因为您不希望丢失迁移后创建的表中的数据,则可以在heroku控制台上使用以下命令放桌子:
$ 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上的远程登台服务器上添加的数据时才有用。
答案 1 :(得分:6)
执行以下命令。这里'abc'是应用名称
heroku run console --app abc
然后使用,
ActiveRecord::Migration.drop_table(:orders)
它将删除表'订单'。
答案 2 :(得分:3)
只需创建这样的迁移:
def self.up
drop_table :orders
end
def self.down
# whatever you need to recreate the table or
# raise IrreversibleMigration
# if you want this to be irreversible.
end
然后在下次推送更改时执行heroku rake db:migrate
。
您可能希望在SQLite中重新创建表,以便您也可以在本地运行此迁移。