慢慢地,"=11=":"=10="
Heroku, Rails: PG::SyntaxError
在 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。您需要添加适当的插件。
看看你的迁移 - 他们有这个吗:options: "ENGINE=InnoDB DEFAULT CHARSET=utf8"
?删除这些并推回到 Heroku 可能会解决这个问题。
更多详情
这可能是 Rails 5 的新功能,并且使得迁移很难保持与数据库无关。选项针对MySQL,指定应该使用InnoDB
存储引擎。
当您推送到 Heroku 时,您的 database.yml
会自动更新为使用 Postgres。但是,您的迁移未受影响,并且引擎参数对 Postgres 无效并导致错误。
这也可能会影响您的 schema.rb
?
在 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。您需要添加适当的插件。
看看你的迁移 - 他们有这个吗:options: "ENGINE=InnoDB DEFAULT CHARSET=utf8"
?删除这些并推回到 Heroku 可能会解决这个问题。
更多详情
这可能是 Rails 5 的新功能,并且使得迁移很难保持与数据库无关。选项针对MySQL,指定应该使用InnoDB
存储引擎。
当您推送到 Heroku 时,您的 database.yml
会自动更新为使用 Postgres。但是,您的迁移未受影响,并且引擎参数对 Postgres 无效并导致错误。
这也可能会影响您的 schema.rb
?