I can't get rake db:migrate to run on my rails 4.0.1 app on Heroku.
我无法获得rake db:迁移到Heroku上运行我的rails 4.0.1应用程序。
I'm guessing that I don't have postgres configured properly... but reading the docs on heroku hasn't really helped and I'm not sure what to do. I don't know too much about heroku or postgres.
我猜我没有正确地配置好postgres……但是在heroku上看医生并没有什么帮助,我也不知道该怎么做。我对heroku和postgres了解不多。
Any help or resources would be greatly appreciated. Let me know if there's anything else I can post.
如有任何帮助或资源,我们将不胜感激。如果我还有什么可以发布的,请告诉我。
(Also, I'm using devise, if that matters)
(如果有关系的话,我也在用设计。)
When I run heroku run rake db:migrate
I get this:
当我运行heroku运行rake db: migration I get this:
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
When I run heroku run rake db:setup
I get this:
当我运行heroku运行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"}
followed by the same PG::UndefinedTable ERROR relation 'users' does not exist
后面是同样的PG:::不可定义的错误关系“用户”不存在
database.yml :
数据库。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:
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 个解决方案
#1
42
I would first try
我第一次尝试
heroku restart
heroku rake db:migrate
If that doesn't work, then try.
如果不行,那就试试。
heroku pg:reset DATABASE_URL #Literally type in heroku pg:reset DATABASE_URL
heroku rake db:migrate
#2
5
I should've read the stack trace more closely. My factories.rb was creating user objects as attributes for other factories. Wrapping them in a block fixed it:
我应该更仔细地读堆栈跟踪。我的工厂。rb将用户对象创建为其他工厂的属性。用块包起来固定:
FactoryGirl screws up rake db:migrate process
工厂女孩搞砸了rake db:迁移过程
#3
4
Run
运行
heroku pg:reset DATABASE_URL
and you are done.
和你做。
#4
2
Jason's answer might fix your problem, but i wanted to expand on why you got the error and how to fix it
Jason的回答可能会解决您的问题,但我想进一步说明为什么会出现这个错误,以及如何解决它
-
you cant run "rake db:setup" on heroku, because it will try to create a databas, and your database already exists on heroku
您不能在heroku上运行“rake db:setup”,因为它将尝试创建一个数据库,并且您的数据库已经存在于heroku上
-
in your database.yml, you should read the database url from the enviroment variable like: production:
在你的数据库。yml,您应该从环境变量中读取数据库url,如:production:
url: <%= ENV["DATABASE_URL"] %>
url:< % = ENV(“DATABASE_URL”)% >
-
i think you are getting the 2nd error because you have some version error in your migrations, runing them from the begining should fix it :
我认为您正在得到第二个错误,因为在您的迁移中有一些版本错误,从一开始运行它们就应该修复它:
rake db:migrate VERSION=0
rake db:migrate VERSION = 0
#5
0
To drop and recreate database
删除和重新创建数据库。
- Login to heroku in terminal
- 在终端登录heroku
- cd into your app
- cd到您的应用程序
- Run
- 运行
heroku pg:reset DATABASE
heroku pg:重置数据库
#1
42
I would first try
我第一次尝试
heroku restart
heroku rake db:migrate
If that doesn't work, then try.
如果不行,那就试试。
heroku pg:reset DATABASE_URL #Literally type in heroku pg:reset DATABASE_URL
heroku rake db:migrate
#2
5
I should've read the stack trace more closely. My factories.rb was creating user objects as attributes for other factories. Wrapping them in a block fixed it:
我应该更仔细地读堆栈跟踪。我的工厂。rb将用户对象创建为其他工厂的属性。用块包起来固定:
FactoryGirl screws up rake db:migrate process
工厂女孩搞砸了rake db:迁移过程
#3
4
Run
运行
heroku pg:reset DATABASE_URL
and you are done.
和你做。
#4
2
Jason's answer might fix your problem, but i wanted to expand on why you got the error and how to fix it
Jason的回答可能会解决您的问题,但我想进一步说明为什么会出现这个错误,以及如何解决它
-
you cant run "rake db:setup" on heroku, because it will try to create a databas, and your database already exists on heroku
您不能在heroku上运行“rake db:setup”,因为它将尝试创建一个数据库,并且您的数据库已经存在于heroku上
-
in your database.yml, you should read the database url from the enviroment variable like: production:
在你的数据库。yml,您应该从环境变量中读取数据库url,如:production:
url: <%= ENV["DATABASE_URL"] %>
url:< % = ENV(“DATABASE_URL”)% >
-
i think you are getting the 2nd error because you have some version error in your migrations, runing them from the begining should fix it :
我认为您正在得到第二个错误,因为在您的迁移中有一些版本错误,从一开始运行它们就应该修复它:
rake db:migrate VERSION=0
rake db:migrate VERSION = 0
#5
0
To drop and recreate database
删除和重新创建数据库。
- Login to heroku in terminal
- 在终端登录heroku
- cd into your app
- cd到您的应用程序
- Run
- 运行
heroku pg:reset DATABASE
heroku pg:重置数据库