ruby-on-rails - Heroku、Rails:PG::SyntaxError

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

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

ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "ENGINE" LINE 1: ...estamp NOT NULL, "updated_at" timestamp 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!


config/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


我做错了什么?

最佳答案

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

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

heroku run rake db:migrate

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

关于ruby-on-rails - Heroku、Rails:PG::SyntaxError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42736529/

相关文章:

ruby-on-rails - 阻止创建一个类的多个对象

SQL SELECT 子句与特定顺序的 WHERE 语句

具有来自子查询的可选结果的 postgresql 列

ruby-on-rails - 在 ruby​​ 中,如何检查不以 9 开​​头的社会安全号码?

ruby-on-rails - 在 Ruby 中递增枚举?

ruby-on-rails - Rails 中的批量 API 调用

sql - 如何确保两列始终等于同一事物

ruby-on-rails - Rails ActionView::MissingTemplate 用于不应该存在的模板

ruby-on-rails - ActionMailer 在 Rails 4.2 中使用哪个 ActiveJob 队列?

ruby-on-rails - 在建立连接之前关闭 WebSocket - Rails 5