i cant seem postgres db link sinatra app using active record. i'm getting following error when run db:migrate
activerecord::nodatabaseerror: fatal: database "localhost/till" not exist i ran dbcreate mydb , went through without problem, , exists.
i have config folder , environment.rb file with
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' ) im referencing file in app.rb thats not problem. gratefully appreciated.
do have migration file using create tables in database? when migrate should generate schema file. create migration file, cd app folder , enter terminal command bundle exec rake db:create_migration name=my_migration_name. create db folder in app folder contain migrate folder. in migrate folder there file. will this:
class migration < activerecord::migration def change end end in change function can create tables. create table add change function create_table function, shown below.
class mymigrationfile < activerecord::migration def change create_table :my_table_name |i| i.string :my_column_name # string type of variable column store, can change if want end end end then create tables need migrate. migrate, or create tables enter terminal command bundle exec rake db:migrate. generate schema file.