New rails postgres app8/12/2023 ![]() Edit: in fact, I didn't even need to do that. To fix that rails error, I just changed the username to 7stud on the three lines in config/database.yml. When I set up postgres, I created the user 7stud, which is my Mac user name. ![]() That error occured because I don't have a database user(or role in postgres speak) named test_postgres-and it's likely no one else will either. Then I tried to execute the migration: ~/rails_projects/test_postgres$ bundle exec rake db:migrateįATAL: role "test_postgres" does not exist ~/rails_projects/test_postgres$ rails g scaffold Post title:string author:string body:textĬreate db/migrate/20130807061320_create_posts.rbĬreate app/controllers/posts_controller.rbĬreate test/controllers/posts_controller_test.rbĬreate app/views/posts/Ĭreate app/views/posts/Ĭreate app/assets/javascripts/posts.js.coffeeĬreate app/assets/stylesheets/Ĭreate app/assets/stylesheets/ Then I created a model: ~/rails_projects$ cd test_postgres/ ![]() (If that is confusing, see: How do I start enterpiseDB PostgreSQL on Mac OSX 10.6.8?) Then I started up postgres, and I used pgAdmin3 to connect to the postgres database server. It turns out, all that does is set up your config/database.yml file like this: development:Īnd the empty sqlite files: development.sqlite3 Okay, to figure out what's going on I created a new test app using the -database flag: rails_projects$ rails new test_postgres -database postgresql # Do not set this db to the same as development or production.ĭatabase: sampleapp_test #can be anything unique # re-generated from your development database when you run "rake". # Warning: The database defined as "test" will be erased and Gem 'spork-rails', github: 'sporkrb/spork-rails'ĭatabase: sampleapp_dev #can be anything unique Do I have to start over? I'm using git if that makes a difference. I read that you can create your rails app with a flag that tells it to use postgres: rails new myapp -database postgresqlīut I already created my app. rw-r-r- 1 7stud staff 0 Jul 30 03:02 test.sqlite3 rw-r-r- 1 7stud staff 0 Jul 30 00:21 development.sqlite3ĭrwxr-xr-x 3 7stud staff 102 Aug 6 22:22 migrate In fact, they are empty: ~/rails_projects/sample_app4_0/db$ ls -alĭrwxr-xr-x 8 7stud staff 272 Aug 6 22:50. = CreateUsers: migrated (0.1500s) =īut in the db directory, I see these files: development.sqlite3įurthermore, when I try to look at those files with the SQLite Database Browser, I get an error that says they are not sqlite 3 databases. Then I created a new app, and in the app I created a User model: $ rails generate model User name:string email:stringĬreate db/migrate/20130806145935_create_users.rbĪnd then I did: $ bundle exec rake db:migrate Then I made the necessary changes to my Gemfile and config/database.yml to use postgres. Technically a user and role are pretty much the same as far as I know.I installed prostgres to use with my rails4 app, and I am able to connect to the database server and create databases. Note: In PostgreSQL a user is simply a role with login permission. Among the two option opt for the seoconde one. The difference is that the first one grants superuser privileges to the Application role while the second grants only the listed permissions to the myapp role.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |