2011-08-26 54 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

相關問題