从schema.rb中删除表

The*_* Oz 2 ruby-on-rails ruby-on-rails-4

我在我的应用程序中有一个Location模型,但后来我退了一步Git,当时我还没有创建模型,然后经过一段时间在另一个分支上工作,我意识到模型已经无处可去了,它是仍然在我的架构中.我试图摆脱它,但它仍然突然冒出来,虽然我的应用程序中没有添加位置迁移文件.什么是摆脱它并清理schema.rb的最佳方法?

更新1

运行

rails销毁模型位置

给我

  invoke  active_record
  remove    /Users/denis/Desktop/migration/templates/create_table_migration.rb
  remove    app/models/location.rb
  invoke    test_unit
  remove      test/models/location_test.rb
  remove      test/fixtures/locations.yml
Run Code Online (Sandbox Code Playgroud)

并且我可以无限期地运行它,它将始终给出相同的结果

运行此迁移:

class DropLocationsTable < ActiveRecord::Migration
  def self.up
    drop_table :locations
  end
end
Run Code Online (Sandbox Code Playgroud)

在rake db:migrate之后给出0结果再次出现在schema.rb中的Locations

更新2

rails db
SQLite version 3.7.12 2012-04-03 19:43:07
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> SELECT * FROM locations;
sqlite> 
Run Code Online (Sandbox Code Playgroud)

Mik*_*del 8

如果你想真正删除它,你应该准备一个迁移来删除表.

如果你只是删除模型,ActiveRecord仍然会在db中找到该表(这可能就是你看到它的原因schema.rb- 如果我是对的你是指文件而不是db模式)

编辑:

所以我试图重现这一点,结果我最终遵循了命令的顺序.

  1. 首先删除表(使用drop_table :locations并运行它进行新的迁移)
  2. 然后运行rails destroy model location(如果你先销毁模型,你会得到一个错误)
  3. 运行,rails c以便Rails获取数据库更改和更新schema.rb