【发布时间】:2008-10-14 16:15:29
【问题描述】:
运行 rake db:migrate 后跟 rake test:units 会产生以下结果:
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 适配器和全新的数据库。 (也就是说,在rake db:migrate 之前运行rm db/*sqlite3 没有帮助。)
test:units 任务是否可能试图重新加载架构?如果是这样,为什么?它不应该识别架构已经是最新的吗?
【问题讨论】:
-
schema.rb 中的 schema_migrations 表肯定没有其他索引声明。不过,有趣的是,该错误不会发生在 MySQL 上。
-
这也可能与我使用table_name_prefix有关。在执行 rake db:schema:load 时,我得到了双前缀表。
标签: ruby-on-rails ruby migration