Heroku,Rails:PG :: SyntaxError

3
当我在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!


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


我的哪里做错了吗?

2个回答

5
您的数据库模式是在Mysql数据库上生成的,并包含Mysql特定选项。在您的情况下,它是ENGINE选项。我不确定是自动生成还是手动添加到迁移中的。
请尝试运行迁移而不是加载模式:
heroku run rake db:migrate

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


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

更多细节

这可能是Rails 5的新特性,使得迁移不易保持数据库无关性。这些选项针对MySQL,指定应使用InnoDB存储引擎。

当你推送到Heroku时,你的database.yml会自动更新为使用Postgres。然而,你的迁移文件没有被修改,引擎参数不适用于Postgres并导致错误。

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


好的,我知道了。我之前查看过我的迁移,它们没有包含任何特定选项。 - heroxav

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接