我是 Ruby 和网络开发的新手。我正在使用带有 Ruby 2.0 的 Windows 7 64 位,并且安装了 PostgreSQL 9.4。
我正在尝试使用 ActiveRecord 创建数据库。我检查了我的 postgresql 服务器是否正在运行,并且执行了 bundle install 以确保我拥有所有必需的 gem。当我运行“bundle exec rake db:create”时,看起来 rake 能够在 PostgreSQL 目录中找到 createdb.exe,但出于某种原因它告诉我我有太多命令行参数:
C:\Users\MH\Desktop\activerecord-template> bundle exec rake db:create
Creating activerecord-template development and test databases if they don't exist...
'createdb': too many command line-arguments (first is "postgres")
我的 Gemfile、Rakefile 和 config.rb 文件位于我之前的帖子中:createdb not recognized as a command when using ActiveRecord
我认为问题可能出在此处的 Rakefile 中:
desc "Create #{APP_NAME} databases"
task "create" do
puts "Creating #{APP_NAME} development and test databases if they don't exist..."
system("createdb #{DB_NAME} --username #{DB_USERNAME} -w --no-password && createdb #{TEST_DB_NAME} --username #{DB_USERNAME} -w --no-password")
end
我尝试删除和更改 -w 的顺序,如下所示:pg_dump: too many command line arguments ,但这并没有解决问题。
还有一些关于将“你的选项放在你的无选项参数之前”的讨论以及这些链接中选项的错误顺序:
http://grokbase.com/t/postgresql/pgsql-general/07avnzajn7/createdb-argument-question
http://postgresql.nabble.com/pgpass-does-not-work-for-createlang-td2118667.html
但我真的不明白这对我的代码意味着什么。
最佳答案
由于您使用的是 Windows,因此该行的语法可能存在问题:
system("createdb #{DB_NAME} --username #{DB_USERNAME} -w --no-password && createdb #{TEST_DB_NAME} --username #{DB_USERNAME} -w --no-password")
如果 Ruby 使用默认的 Windows cmd.exe
来运行命令,&&
运算符将不起作用。
我可能会把它分成 2 个语句:
ok = system("createdb #{DB_NAME} --username #{DB_USERNAME} -w --no-password")
ok &&= system("createdb #{TEST_DB_NAME} --username #{DB_USERNAME} -w --no-password")
# ...can check "ok" for success of both calls if you like...
最后,如果问题仍然存在,则 PATH 中必须有另一个 createdb
可执行文件,它在您的 Postgres 二进制文件路径之前被命中。您可以尝试 system("path")
并查看输出是什么,并检查这些目录是否存在冲突的 createdb
。
关于ruby - 创建 : too many command line arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30767865/