ruby-on-rails - Heroku不会为Rails 3.2创建postgres数据库表(以及数据库本身)

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

我一直在尝试将Rails applicaton部署到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


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

最佳答案

您必须仔细阅读错误消息。

undefined method `has_attached_file' for User(Table doesn't exist):Class


has_attached_file是回形针方法,在您的Gemfile中看不到回形针gem。

希望这可以帮到你。

关于ruby-on-rails - Heroku不会为Rails 3.2创建postgres数据库表(以及数据库本身),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19897966/

相关文章:

ruby - 按可能为 nil 的属性对对象的 ruby​​ 数组进行排序

android - DBFlow Android 选择最常见的值

java - android 上的 noob SQLite 光标错误

ruby-on-rails - 在单个继承表和另一个表中的类之间建立多对多关联

ruby-on-rails - Rails + tinymce-rails 奇怪的错误

ruby - 正则表达式 : back-reference an optional grouping

c# - 使用 Sqlite.NET 的 Entity Framework 提示不支持应用连接

ruby-on-rails - 安装 posix spawn 时出现 UTF-8 设置问题

ruby-on-rails - Rails 还是 Sinatra? PHP程序员入门学习哪个好?

ruby - 如何避免 ruby​​ block 中的重复代码?