Ruby ActiveRecord、Sinatra和Postgres-无法链接到我的数据库

Ruby ActiveRecord、Sinatra和Postgres-无法链接到我的数据库,ruby,postgresql,sinatra,sinatra-activerecord,Ruby,Postgresql,Sinatra,Sinatra Activerecord,我似乎无法使用Active record让我的Postgres db链接到我的Sinatra应用程序。当我运行db:migrate时,出现以下错误 ActiveRecord::NoDatabaseError: FATAL: database "localhost/till" does not exist 我运行了dbcreatemydb,这一过程毫无问题,而且它确实存在 我有一个配置文件夹和一个带有 db = URI.parse(ENV['DATABASE_URL'] || 'postgre

我似乎无法使用Active record让我的Postgres db链接到我的Sinatra应用程序。当我运行db:migrate时,出现以下错误

ActiveRecord::NoDatabaseError: FATAL:  database "localhost/till" does not exist
我运行了dbcreatemydb,这一过程毫无问题,而且它确实存在

我有一个配置文件夹和一个带有

db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/mydb')

ActiveRecord::Base.establish_connection(
  adapter: db.scheme == 'postgres' ? 'postgresql' : db.scheme,
  host: db.host,
  username: db.user,
  password: db.password,
  database: db.path[1..-1],
  encoding: 'utf8'
)

我引用了我app.rb中的文件,所以这不是问题所在。非常感谢您的帮助。

您是否有用于在数据库中创建表的迁移文件?当您迁移时,应该生成架构文件。要创建迁移文件,请将
cd
复制到应用程序文件夹,然后输入终端命令
bundle exec rake db:create_migration NAME=my_migration_NAME
。这将在应用程序文件夹中创建一个
db
文件夹,其中将包含一个
migrate
文件夹。在
migrate
文件夹中将有一个文件。看起来是这样的:

class Migration < ActiveRecord::Migration
  def change
  end
end

然后实际创建需要迁移的表。要迁移或实际创建表,请输入终端命令
bundle exec rake db:migrate
。这将生成您的模式文件。

在迁移之前是否运行了
rake db:create
?是的。我删除了三个///中的一个,现在我得到了Errno::enoint:没有这样的文件或目录@rb_sysopen-db/schema.rb。我是否必须以某种方式生成模式?
class MyMigrationFile < ActiveRecord::Migration
  def change
    create_table :my_table_name do |i|
      i.string :my_column_name
      # string is the type of variable this column will store, you can change that if you want
    end
  end
end