Heroku Drop Table Rails帮助

我正在使用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控制台上使用以下命令删除表:

 $ 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上的远程登台服务器上添加的数据时才有用。

执行以下命令。这里’abc’是应用程序名称

 heroku run console --app abc 

然后使用,

 ActiveRecord::Migration.drop_table(:orders) 

它将删除表’订单’。

只需创建这样的迁移:

 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下次推送更改时heroku rake db:migrate

您可能希望在SQLite中重新创建表,以便您也可以在本地运行此迁移。