Reputation: 33635
Running migration on a fresh db results in the following error.
>> 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
The SQL query generated should not include RETURNING "id"
since the schema_migrations table does not have ids.
If I attempt to migrate the database after the failure, it succeeds:
>> rake db:migrate
== CreateSomething: migrating ================================================
-- create_table(:somethings)
-> 0.0041s
== CreateSomething: migrated (0.0042s) =======================================
I'm currently running PostgreSQL 9.2.4, Rails 4.0.0, pg gem 0.16.0 on OS X 10.8.
The sole migration:
class CreateSomething < ActiveRecord::Migration
def change
create_table :somethings do |t|
t.integer :x
t.integer :y
end
end
end
Note: I have tried this migration in other Rails projects, and it works. Something else is amiss, but I'm not sure where to start.
Stack trace is available on pastebin.
Upvotes: 4
Views: 745
Reputation: 72544
In my case this problem was caused by the attribute_normalizer gem. (See issue 42) It only happened with a completely empty database after the very first migration.
Using the 1.2 prerelease fixed the problem.
Upvotes: 5
Reputation: 176552
When you setup a fresh database, you should not run rake db:migrate
. Instead, you should use rake db:schema:load
.
The migration system is designed to update a schema. On a fresh install is faster and more convenient to load the latest schema immediately.
Upvotes: 0