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中重新创建表,以便您也可以在本地运行此迁移。
- Heroku上的ffmpeg:无法识别的选项’预设’
- 使用AWS RDS在Heroku App上获取Mysql2 :: Error(SSL连接错误:ASN:错误的其他签名确认)
- 在heroku上的PostgreSQL数据库中存储超过255个字符
- Heroku + Rails错误ActiveRecord :: StatementInvalid
- 部署到heroku时,与fontawesome的Rails编译器错误
- Rails 3.2:Heroku推送拒绝,没有检测到Cedar支持的应用程序
- Rails教程chapter3 heroku找不到控制器StaticPagesController
- 了解Heroku上的Rails应用程序初始化
- Heroku Rails Net :: HTTP:OpenSSL :: SSL :: SSLError:SSL_connect返回= 1 errno = 0状态= SSLv3读取服务器证书B:证书validation失败