gpt4 book ai didi

ruby-on-rails - 如何在 AWS Elastic Beanstalk 上为 Rails 应用程序播种数据库

转载 作者:行者123 更新时间:2023-12-04 01:49:31 27 4
gpt4 key购买 nike

我在本地构建了一个小型 Rails 应用程序,并尝试将其部署到 AWS Elastic Beanstalk。

这是我一直遵循的指南:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Ruby_rails.html

部署成功,但没有进行数据库播种,因此我所有的静态列表值都是空的。

虽然我认为这不是“理想”的解决方案,但我确实尝试通过 SSH 连接到 EB 实例来手动为数据库播种。

eb ssh
cd /var/app/current/
rake db:seed

然后结果是:

[ec2-user@ip-172-31-13-16 current]$ rake db:seed
Rails Error: Unable to access log file. Please ensure that /var/app/current/log/production.log exists and is writable (ie, make it writable for user and group: chmod 0664 /var/app/current/log/production.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.
ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
(0.1ms) begin transaction

...

(0.1ms) rollback transaction
rake aborted!
ActiveRecord::StatementInvalid: SQLite3::ReadOnlyException: attempt to write a readonly database: INSERT INTO "users" ("first_name", "last_name", "email", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?)
/var/app/current/db/seeds.rb:9:in `<top (required)>'
SQLite3::ReadOnlyException: attempt to write a readonly database
/var/app/current/db/seeds.rb:9:in `<top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)

执行此操作的正确方法是什么?

提前致谢!

最佳答案

这两个错误(无法访问日志文件attempt to write a readonly database)都是由于文件访问权限引起的。

当您通过 ssh 连接到 EC2 实例时,您通常以对 capistrano 部署目录没有写入权限的用户身份登录。 (您具有读取权限,因此您可以查看文件,但不能写入 - 因此您无法写入日志或创建新的 sqlite 数据库文件)。

您可以使用 sudo 以其他用户身份运行 rake:

sudo -u app env PATH=$PATH RAILS_ENV=production bundle exec rake db:seed

(将“-u app”更改为您的应用程序运行时使用的任何用户名 - 或者将其保留以仅以 root 身份运行命令)

关于ruby-on-rails - 如何在 AWS Elastic Beanstalk 上为 Rails 应用程序播种数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936042/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com