Rails searches for Nonexistent ID column in schema_migrations table during initial migration

Running migration to a new 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 generated SQL query must not include RETURNING "id" because the schema_migrations table has no identifiers.

If I try to migrate the database after the failure, it will succeed:

 >> rake db:migrate == CreateSomething: migrating ================================================ -- create_table(:somethings) -> 0.0041s == CreateSomething: migrated (0.0042s) ======================================= 

I am currently running PostgreSQL 9.2.4, Rails 4.0.0, pg gem 0.16.0 on OS X 10.8.

Single Migration:

 class CreateSomething < ActiveRecord::Migration def change create_table :somethings do |t| t.integer :x t.integer :y end end end 

Note. I tried this migration in other Rails projects and it works. Something else is wrong, but I'm not sure where to start.

A stack trace is available on pastebin .

+4
source share
2 answers

When setting up a new database, you should not run rake db:migrate . Instead, you should use rake db:schema:load .

The migration system is designed to update the scheme. With a new installation, it’s faster and more convenient to download the latest circuit right away.

0
source

In my case, this problem was caused by the attribute_normalizer gem. (See question 42 ) This only happened with a completely empty database after the very first migration.

Problem 1.2 fixed the problem.

+5
source

Source: https://habr.com/ru/post/1495437/


All Articles