Jak*_*ake 8 ruby database ruby-on-rails heroku
我正在使用Ruby on Rails,我不再需要我的表,Order
所以我使用SQLite管理器删除了它.如何在heroku中删除表?
编辑我收到错误
db/migrate/20110806052256_droptableorders.rb:10: syntax error, unexpected keyword_end, expecting $end
Run Code Online (Sandbox Code Playgroud)
当我运行命令
class DropTableOrder < ActiveRecord::Migration
self.up
drop_table :orders
end
self.down
raise IrreversibleMigration
end
end
Run Code Online (Sandbox Code Playgroud)
Zee*_*han 21
如果您不想创建迁移到删除表并且无法回滚以前的迁移,因为您不希望丢失迁移后创建的表中的数据,则可以在heroku控制台上使用以下命令删除表:
$ heroku console
Ruby console for heroku-project-name
>> ActiveRecord::Migration.drop_table(:orders)
Run Code Online (Sandbox Code Playgroud)
上面的命令会从heroku数据库中删除表.您可以在ActiveRecord :: Migration模块中使用其他方法(如create_table,add_column,add_index等)来操作数据库,而无需创建和运行迁移.但请注意,这将在Rails创建的schema_migrations表中留下一堆混乱,用于管理迁移版本.
这仅在您的应用程序仍在开发中且您不想丢失在heroku上的远程登台服务器上添加的数据时才有用.
执行以下命令.这里'abc'是应用程序名称
heroku run console --app abc
Run Code Online (Sandbox Code Playgroud)
然后使用,
ActiveRecord::Migration.drop_table(:orders)
Run Code Online (Sandbox Code Playgroud)
它将删除表'订单'.
只需创建一个像这样的迁移:
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
Run Code Online (Sandbox Code Playgroud)
然后在heroku rake db:migrate
下次推送更改时执行 a 。
您可能希望在 SQLite 中重新创建表,以便也可以在本地运行此迁移。