運行rake db:migrate
其次rake test:units
產生如下:如何在Rails中解決「index unique_schema_migrations already exists」的問題?
rake test:functionals
(in /projects/my_project)
rake aborted!
SQLite3::SQLException: index unique_schema_migrations already exists: CREATE UNIQUE INDEX "unique_schema_migrations" ON "ts_schema_migrations" ("version")
的db/schema.rb
相關部分如下:
create_table "ts_schema_migrations", :id => false, :force => true do |t|
t.string "version", :null => false
end
add_index "ts_schema_migrations", ["version"], :name => "unique_schema_migrations", :unique => true
我不會在任何地方手動更改該指數,而我使用Rails '具有全新數據庫的默認SQLite3適配器。 (也就是說,運行rm db/*sqlite3
之前rake db:migrate
沒有幫助。)
是否test:units
任務可能試圖重新加載架構?如果是這樣,爲什麼?它不應該認識到模式已經是最新的嗎?
schema.rb中的schema_migrations表肯定沒有其他索引聲明。雖然這個bug在MySQL上不會發生,但有趣的是, – 2008-10-14 17:12:11
它也可能與我使用table_name_prefix有關。當執行rake db:schema:load時,我得到雙重前綴的表。 – 2008-10-14 17:12:53