Rake db:setup或rake db:create应用错误的用户名/错误的数据库

编程入门 行业动态 更新时间:2024-10-19 02:25:27
本文介绍了Rake db:setup或rake db:create应用错误的用户名/错误的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用Mac OSX Yosemite(10.10.4):

Using Mac OSX Yosemite (10.10.4):

rails -v => Rails 4.2.3

ruby​​ -v =>红宝石2.2.2p95

下面是这些指令的组合: www.digitalocean/community/tutorials/how-to-setup-ruby- on-rails-with-postgres 和以下说明: blog.endpoint/2014/03/setup-rails-environment-with-postgresql.html

Followed a combination of these instructions: www.digitalocean/community/tutorials/how-to-setup-ruby-on-rails-with-postgres and these instructions: blog.endpoint/2014/03/setup-rails-environment-with-postgresql.html

bash:

$createuser -P -d -e project (This was successful) $password: aPassword $re-enter password: aPassword $rails new project --database=postgresql $cd project/config/database.yml

这是config / database.yml:

Here is the config/database.yml:

default: &default adapter: postgresql encoding: unicode username: bespoke password: <%= ENV['PROJECT_DATABASE_PASSWORD'] %> #if I type env in bash => PROJECT_DATABASE_PROJECT: aPassword pool: 5 development: <<: *default database: Project_development test: <<: *default database: Project_test

到目前为止非常好。 ..但随后:

So far so good... but then:

rake db:create 第一次: myusername已经存在 第二次: rake db:setup 我相信它们应该是相同的东西...

rake db:create The first time: myusername already exists Second time: rake db:setup I believe they're supposed to be the same things...

myusername already exists Project_test already exists /Users/myusername/Challenges/Project/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /Users/myusername/Challenges/Project/config/application.rb to limit the frameworks that will be loaded.

换句话说,问题是: rake db:create 或 rake db:setup 似乎能够执行相同的操作,因此能够创建表 Project_test 他们说已经创建了 Project_test ...,但是他们拒绝创建表 Project_development ,而是坚持要求我使用表 myusername 此处未列出任何地方!!

So in other words the problem is: rake db:create or rake db:setup which seem to do the same exact were able to create the table Project_test hence they say Project_test already created... but they refused to create the table Project_development and instead insist on having me use the table myusername which is not listed anyWHERE~!

我尝试删除默认值并将其硬编码到开发中有用。顺便说一下,这里是 psql => / list

I have tried removing the default and hardcoding it into development to no avail. By the way here is output of psql=> /list

List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges --------------+---------+----------+-------------+-------------+------------------- Project_test | project | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | mee | UTF8 | en_US.UTF-8 | en_US.UTF-8 | myusername | mee | UTF8 | en_US.UTF-8 | en_US.UTF-8 |

这证明它确实创建了测试数据库并使用了正确的所有者/用户,但拒绝创建开发数据库。

Which proves that it did create the test database and used the correct Owner/user but it refused to create the development database.

我做错了还是应该问他们的github问题?

What am I doing wrong or should I ask their github issues?

推荐答案

已解决!这是一个环境变量。首先,我使用env查看所有变量,并注意到已设置DATABASE_URL。

Solved! It was an environment variable. First, I used env to see all the variables and noticed a DATABASE_URL was set.

$env ... DATABASE_URL=postgres:///steve ...

所以我认为,环境变量可能优先于< appname> _development (但在生成< appname> _test )然后,我查看了我的.zshrc文件,并看到在哪里设置了该值:

So I thought, maybe the environment variable is taking precedent over <appname>_development (but not applied when generating <appname>_test) Then, I looked at my .zshrc file and saw where this value was being set:

➜ ~ cat .zshrc # Added by Steve for permanent path vars export DATABASE_URL=postgres:///$(whoami)

一旦我注释掉了此导出行,然后重新加载/重新启动shell,运行 rake db:create 会生成 < appname> _development 。

Once I commented out this export line, then reloaded/restarted shell, running rake db:create generates <appname>_development as it should.

我不记得为什么需要设置默认值,但是我很高兴在配置文件中记下了一个注释,也许遵循了使用postgres客户端的指南命令行。 希望对别人有帮助

I don't remember why I needed to set that default but I'm glad I made a note in the config file, perhaps following a guide for using postgres client via the command line. Hope that helps someone else

更多推荐

Rake db:setup或rake db:create应用错误的用户名/错误的数据库

本文发布于:2023-10-15 03:07:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1493066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   用户名   数据库   db   Rake

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!