1不能创建数据库

1不能创建数据库

本文介绍了Heroku上的Rails 4.0.1不能创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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



任何帮助或资源将不胜感激。



(另外,我使用的是设计,如果有的话)



当我运行 heroku运行rake db:migrate 我得到这个:

 运行`rake db:migrate`附加到终端... up,run.5077 
PG :: UndefinedTable:ERROR:关系users不存在
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:关系users不存在
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:数据库的权限被拒绝postgres
详细信息:用户没有CONNECT权限。

...堆栈跟踪...

无法为{adapter=>postgresql,username=>aqofwrwjifcqkx创建数据库,password=>7yqDAx1L_4HFhw7WV3PH7ZrKyM,port=> 5432,database=>d5dvi0pjk7dgr7,host=>ec2-23-21-94-137.compute-1。 amazonaws.com}

后跟相同的PG :: UndefinedTable错误关系'users'不存在

database.yml:

 开发:
适配器:sqlite3
编码:unicode
数据库:chore_app_development
池:5

测试:
适配器:sqlite3
编码:unicode
数据库:chore_app_test
池:5

生产:
适配器:postgresql
数据库:chore_app_production
池:5
超时:5000 $



c $ c> source'https://rubygems.org'
ruby​​'2.0.0'

gem'rails','4.0.1'

#数据库e
组:生产do
gem'pg'
结束

组:开发,:测试
gem'sqlite3'
结束

#资产
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 b
$ b#应用程序
gem'devise'
gem'formtastic'

#测试
gem'factory_girl_rails'


解决方案 div>

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


I can't get rake db:migrate to run on my rails 4.0.1 app on Heroku.

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.

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:

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:

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

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'
解决方案

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:

FactoryGirl screws up rake db:migrate process

这篇关于Heroku上的Rails 4.0.1不能创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 01:12