2011-08-26 52 views

回答

3

您可以直接查询迁移表的内容。你会回来的迁移表包含一切哈希的数组,它会告诉你哪些迁移当前起来:

# Get the SQL connection adapter 
connection = ActiveRecord::Base.connection 

# Get the migrations table name 
migrations_table = ActiveRecord::Migrator.schema_migrations_table_name 

# Execute query 
connection.execute("select * from #{migrations_table}") 
+1

对于Rails开发2.1及以上,运行迁移存储在'schema_migrations'表在db ,所以第2步可能会被跳过,只需执行'connection.execute(“select * from schema_migrations”)'。请参阅:http://api.rubyonrails.org/classes/ActiveRecord/Migration.html#class-ActiveRecord::Migration-label-About+the+schema_migrations+table – lacostenycoder

相关问题