Heroku,Rails:PG :: SyntaxError

时间:2017-03-11 14:44:40

标签: ruby-on-rails ruby postgresql heroku heroku-postgres

在heroku上的Rails 5.1应用程序中加载架构时,会引发以下异常:

  

ActiveRecord :: StatementInvalid:PG :: SyntaxError:ERROR:“ENGINE”处或附近的语法错误   第1行:... estamp NOT NULL,“updated_at”时间戳NOT NULL)ENGINE = Inn ...

详细信息:

微量

-- create_table("ads_dashboard_campaigns", {:force=>:cascade, :options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8"})
   (5.0ms)  DROP TABLE IF EXISTS "ads_dashboard_campaigns" CASCADE
   (7.3ms)  CREATE TABLE "ads_dashboard_campaigns" ("id" bigserial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8
rails aborted!


配置/ database.yml的

# # SQLite version 3.x
# #   gem install sqlite3-ruby (not necessary on OS X Leopard)
# development:
#   adapter: sqlite3
#   database: db/development.sqlite3
#   pool: 5
#   timeout: 5000

# # Warning: The database defined as "test" will be erased and
# # re-generated from your development database when you run "rake".
# # Do not set this db to the same as development or production.
# test:
#   adapter: sqlite3
#   database: db/test.sqlite3
#   pool: 5
#   timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000


# Custom stuff
development:
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: slooob_development
  username: root
  password: 0402Jonas
  port: 3306

test:
  adapter: mysql2
  encoding: utf8
  pool: 5
  database: slooob_test
  username: root
  password: 0402Jonas
  port: 3306

旁注:我知道Heroku使用PostgreSQL数据库,但在将开发和测试数据库设置为MySQL之前,使用默认的生产设置已经有效。我还尝试将适配器设置为postgresql

我做错了什么?

2 个答案:

答案 0 :(得分:5)

您的数据库架构是在Mysql数据库上生成的,包含特定于Mysql的选项。在您的情况下,它是ENGINE选项。我不确定它是自动生成还是您手动将这些选项添加到迁移中。

尝试运行迁移,而不是加载架构:

heroku run rake db:migrate

你也可以在Heroku上使用Mysql。您需要添加适当的插件。

答案 1 :(得分:1)

查看您的迁移 - 他们是否有这个:options: "ENGINE=InnoDB DEFAULT CHARSET=utf8"?删除这些并推回到Heroku可能会解决问题。

更多细节

这可能是Rails 5的新功能,并且使迁移难以与数据库无关。选项针对MySQL,并指定应使用InnoDB存储引擎。

当您向上推进Heroku时,您的database.yml会自动更新为使用Postgres。但是,您的迁移不受影响,并且引擎参数对Postgres无效并导致错误。

这可能也会影响您的schema.rb