Heroku上的Rails 4.0.1,无法创建数据库

时间:2013-11-29 21:58:53

标签: ruby-on-rails ruby heroku ruby-on-rails-4 rails-postgresql

我无法获得rake db:migrate在Heroku上的rails 4.0.1 app上运行。

我猜我没有正确配置postgres ...但是阅读heroku上的文档并没有真正帮助,我不知道该怎么做。我对heroku或postgres不太了解。

非常感谢任何帮助或资源。如果还有其他我可以发布的内容,请告诉我。

(另外,我正在使用设计,如果重要的话)

当我运行heroku run rake db:migrate时,我明白了:

Running `rake db:migrate` attached to terminal... up, run.5077
PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 5:                WHERE a.attrelid = '"users"'::regclass
                                      ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                 pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
            FROM pg_attribute a LEFT JOIN pg_attrdef d
              ON a.attrelid = d.adrelid AND a.attnum = d.adnum
           WHERE a.attrelid = '"users"'::regclass
             AND a.attnum > 0 AND NOT a.attisdropped
           ORDER BY a.attnum

rake aborted!
PG::UndefinedTable: ERROR:  relation "users" does not exist
LINE 5:                WHERE a.attrelid = '"users"'::regclass
                                      ^
:               SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                 pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
            FROM pg_attribute a LEFT JOIN pg_attrdef d
              ON a.attrelid = d.adrelid AND a.attnum = d.adnum
           WHERE a.attrelid = '"users"'::regclass
             AND a.attnum > 0 AND NOT a.attisdropped
           ORDER BY a.attnum

当我运行heroku run rake db:setup时,我明白了:

FATAL:  permission denied for database "postgres"
DETAIL:  User does not have CONNECT privilege.

... stack trace ...

Couldn't create database for {"adapter"=>"postgresql", "username"=>"aqofwrwjifcqkx", "password"=>"7yqDAx1L_4HFhw7WV3PH7ZrKyM", "port"=>5432, "database"=>"d5dvi0pjk7dgr7", "host"=>"ec2-23-21-94-137.compute-1.amazonaws.com"}

后跟相同的PG :: UndefinedTable ERROR关系'用户'不存在

database.yml:

development:
  adapter: sqlite3
  encoding: unicode
  database: chore_app_development
  pool: 5

test:
  adapter: sqlite3
  encoding: unicode
  database: chore_app_test
  pool: 5

production:
  adapter: postgresql
  database: chore_app_production
  pool: 5
  timeout: 5000

的Gemfile:

source 'https://rubygems.org'
ruby '2.0.0'

gem 'rails', '4.0.1'

# Database
group :production do
  gem 'pg'
end

group :development, :test do
  gem 'sqlite3'
end

# Assets
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'turbolinks'
gem 'haml-rails'
gem 'jquery-rails'

# Heroku
gem 'rails_12factor', group: :production

# Application
gem 'devise'
gem 'formtastic'

# Testing
gem 'factory_girl_rails'

5 个答案:

答案 0 :(得分:47)

我会先尝试

heroku restart

heroku rake db:migrate

如果这不起作用,请尝试。

heroku pg:reset DATABASE_URL   #Literally type in heroku pg:reset DATABASE_URL

heroku rake db:migrate

答案 1 :(得分:5)

我应该更仔细地阅读堆栈跟踪。我的factories.rb正在创建用户对象作为其他工厂的属性。将它们包裹在一个块中固定它:

FactoryGirl screws up rake db:migrate process

答案 2 :(得分:4)

运行

heroku pg:reset DATABASE_URL

你已经完成了。

答案 3 :(得分:2)

Jason的回答可能会解决您的问题,但我想扩展您遇到错误的原因以及解决方法。

  1. 你不能在Heroku上运行“rake db:setup”,因为它会尝试创建一个数据库,你的数据库已经存在于Heroku上

  2. 在您的database.yml中,您应该从环境变量中读取数据库URL,如: 制作:<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script> <div id="app"/>

  3. 我认为您收到第二个错误,因为您的迁移中存在一些版本错误,从一开始就运行它们应该修复它: url: <%= ENV["DATABASE_URL"] %>

答案 4 :(得分:0)

删除并重新创建数据库

  1. 登录终端
  2. 中的heroku
  3. 进入您的应用
  4. 运行
  5.   

    heroku pg:reset DATABASE