Ruby on rails Heroku Drop Table Rails帮助
我正在使用RubyonRails,我不再需要我的表Ruby on rails Heroku Drop Table Rails帮助,ruby-on-rails,ruby,database,heroku,Ruby On Rails,Ruby,Database,Heroku,我正在使用RubyonRails,我不再需要我的表Order,所以我使用SQLite管理器删除了它。。如何在heroku中删除表 编辑 我发现了错误 db/migrate/20110806052256_droptableorders.rb:10: syntax error, unexpected keyword_end, expecting $end 当我运行命令时 class DropTableOrder < ActiveRecord::Migration self.up
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
class DropTableOrder
只需创建如下迁移:
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中重新创建表,以便也可以在本地运行此迁移。如果您不想创建迁移以删除表,并且无法回滚以前的迁移,因为您不想丢失迁移后创建的表中的数据,您可以在heroku控制台上使用以下命令删除表:
$ heroku console
Ruby console for heroku-project-name
>> ActiveRecord::Migration.drop_table(:orders)
上面的命令将从heroku数据库中删除该表。您可以在ActiveRecord::Migration模块中使用其他方法,如创建\表、添加\列、添加\索引等来操作数据库,而无需创建和运行迁移。但请注意,这将在Rails为管理迁移版本而创建的schema_migrations表中留下混乱
只有当您的应用程序仍在开发中,并且您不想丢失在heroku上的远程登台服务器上添加的数据时,此命令才有用。执行以下命令。此处的“abc”是应用程序名称
heroku run console --app abc
然后用,
ActiveRecord::Migration.drop_table(:orders)
它将删除表“订单”。我收到一个错误。==DropTablesMigration:迁移==================================================--DropTable(:order)rake中止!发生错误,此迁移和所有后续迁移已取消:PGError:error:table“order”不存在:DROP table“order”。但我点的桌子还是有exist@Jake:抱歉,输入错误,它应该是
:orders
而不是:order
。我在本地服务器上重新创建了表order
,并尝试使用您的命令将其删除。你能在顶部检查一下我的编辑吗made@Jake字体抱歉(再次),今晚我好像全是打字错误。Missingdef
添加了。@Jake:不,3.1与我的大脑和手指之间没有通信无关:)我在开发时发现这很有用,当时我在推/拉db,不知怎的把它搞乱了&迁移正在消亡。这个命令非常有效,谢谢!