【发布时间】:2013-11-22 18:13:54
【问题描述】:
我一直在尝试将我的 Rails 应用程序部署到 Heroku。它在我的计算机上使用回形针和 SQLite,我正在尝试在我的计算机上使用 SQLite,在 Heroku 上使用 PostgreSQL。
这是我的 Gemfile:
ruby '1.9.3'
gem 'rails', '3.2.9'
group :production do
gem "pg"
gem 'thin'
gem 'rails_12factor', '0.0.2'
end
group :development, :test do
gem "sqlite3"
gem "pg"
end
我的配置/database.yml:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
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: &test
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
database: tagitpostgree
pool: 5
timeout: 5000
cucumber:
<<: *test
我在 Heroku 也遇到过这类错误。我猜数据库没有被创建?有什么提示吗?
我得到的错误如下:
C:\Sites\tag-it>heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.3193
Connecting to database specified by DATABASE_URL
rake aborted!
undefined method `has_attached_file' for User(Table doesn't exist):Class
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
/app/app/models/user.rb:17:in `<class:User>'
我的迁移:
ls db/migrate
20121128000354_devise_create_users.rb
20121128000910_rolify_create_roles.rb
20121128000933_add_name_to_users.rb
20130827150824_create_data_files.rb
20130827154510_add_attachment_avatar_to_users.rb
20130827162448_add_avatar_to_users.rb
20130827183819_add_project_to_projects.rb
20130827191647_add_attachment_video_to_projects.rb
20130827195845_create_tags.rb
20130827211446_add_project_id_to_tags.rb
20130827213541_add_user_id_to_tags.rb
20130831173534_create_projectparticipants.rb
20130831184444_add_project_id_to_projectparticipants.rb
20130831184522_add_user_id_to_projectparticipants.rb
20130831190120_adicionando_index.rb
20130908135549_add_college_to_users.rb
20130908143105_add_function_to_users.rb
20130908143303_add_course_to_users.rb
【问题讨论】:
-
在以后的问题中,请花时间确保您的错误代码的格式和包装正确。当它们不容易阅读时,您会阻止潜在的回答者帮助您。
-
您确定您的迁移顺序正确吗?另外,看起来您使用的是回形针之类的东西?这是在您的 Gemfile 中吗?错误消息告诉您正在尝试在 User 表上创建列,但 User 表不存在。如果迁移顺序错误,有时会发生这种情况
-
您能发布
db/migrate/中的文件吗?您确定在尝试运行heroku run rake db:migrate之前已将所有这些文件添加到git 并将它们推送到您的heroku git 远程吗?一些不相关的问题:heroku 默认从您的DATABASE_URL环境变量生成database.yml,因此除非您使用自定义构建包或其他东西,否则不会使用database.yml中的production配置。此外,如果您不在本地使用 postgres,我认为您的开发/测试组中不需要pggem。 -
顺便说一句,您应该在本地安装 PostgreSQL 或在 postgres.heroku.com 创建一个 dev PostgreSQL 实例,以避免将来无法开发和生产。
-
抱歉格式化,这是我在这里的第一篇文章。第一个数据库迁移创建一个用户表。 Paperclip 在我的 Gemfile 中,我刚刚在上面发布了其中的一部分。我如何知道 Heroku 的数据库设置?我要在那里创建一个新的数据库吗?
标签: ruby-on-rails ruby sqlite heroku heroku-postgres