0

As described in the title, I have a migration in my Rails app which creates a table. We have a Postgres database. When I run the migration in development, it fails:

ActiveRecord::StatementInvalid: PG::Error: ERROR:  current transaction is aborted, commands ignored until end of transaction block
: CREATE TABLE "feedback_questions" ("id" serial primary key, "survey_id" integer, "question_text" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 

The migration is long, but the table creation is the first thing that happens. It looks like this:

def up
  create_table :feedback_questions do |t|
    t.integer :survey_id
    t.text :question_text

    t.timestamps
  end
  # ...
end

It looks to me like this isn't an issue with the migration, but with the database (the error is coming from PG). The error message is similar to this question, but it's not saying anything about what's wrong - just that there's an error. (Also, the table doesn't exist yet; I've checked.)

How can I get more data to debug this?

Community
  • 1
  • 1
pjmorse
  • 9,204
  • 9
  • 54
  • 124

1 Answers1

0

The error message was a red herring. The issue was not with the table creation; the issue was with the format of the migration itself. I was defining a few models in the migration which used tables created in the #up method. When rake tried to start the migration, it looked for tables for those rows, and flipped when it couldn't find them. The create statement just happened to be the first command not run after the error.

pjmorse
  • 9,204
  • 9
  • 54
  • 124