【问题标题】:Rails migration fails creating table in PostgresRails 迁移无法在 Postgres 中创建表
【发布时间】:2014-12-10 14:56:48
【问题描述】:

如标题中所述,我在我的 Rails 应用程序中有一个迁移,它创建了一个表。我们有一个 Postgres 数据库。当我在开发中运行迁移时,它失败了:

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) 

迁移过程很长,但首先要创建表。它看起来像这样:

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

    t.timestamps
  end
  # ...
end

在我看来这不是迁移的问题,而是数据库的问题(错误来自 PG)。错误消息类似于this question,但它并没有说明什么是错误的——只是有一个错误。 (另外,该表还不存在;我已经检查过了。)

如何获取更多数据来调试它?

【问题讨论】:

    标签: ruby-on-rails postgresql rails-migrations


    【解决方案1】:

    错误消息是一条红鲱鱼。问题不在于表的创建;问题在于迁移本身的格式。我在迁移中定义了一些模型,这些模型使用了在 #up 方法中创建的表。当 rake 尝试开始迁移时,它会查找这些行的表,并在找不到它们时翻转。 create 语句恰好是错误后运行的第一个命令not

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 2012-10-01
      • 2018-03-06
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      相关资源
      最近更新 更多