在新数据库上运行迁移会导致以下错误。
>> rake db:drop; rake db:create:all; rake db:migrate
1 activity-image-additions-!?
== CreateSomething: migrating ================================================
-- create_table(:somethings)
-> 0.0042s
== CreateSomething: migrated (0.0043s) =======================================
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::UndefinedColumn: ERROR: column "id" does not exist
LINE 1: ...O "schema_migrations" ("version") VALUES ($1) RETURNING "id"
^
: INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "id
生成的 SQL 查询不应包含RETURNING "id"
,因为 schema_migrations 表没有 ID。
如果我在失败后尝试迁移数据库,它会成功:
>> rake db:migrate
== CreateSomething: migrating ================================================
-- create_table(:somethings)
-> 0.0041s
== CreateSomething: migrated (0.0042s) =======================================
我目前在 OS X 10.8 上运行 PostgreSQL 9.2.4、Rails 4.0.0、pg gem 0.16.0。
唯一的迁移:
class CreateSomething < ActiveRecord::Migration
def change
create_table :somethings do |t|
t.integer :x
t.integer :y
end
end
end
注意:我已经在其他 Rails 项目中尝试过这种迁移,并且它有效。还有其他问题,但我不知道从哪里开始。
堆栈跟踪可在 pastebin 上找到。