Under Schemas, I could see a Tables directory that contained a posts directory, so the table got created, but I couldn't figure out how to see if there were any entries in the table. Then I searched through the test_postgres_development directory for a long time, with no luck. First, I refreshed the 'Databases(3)' line in pgAdmin3 by right clicking on the line and choosing 'Refresh'. Then using pgAdmin3, I tried to find the posts in the test_postgres_development database. Then I started a server: ~/rails_projects/test_postgres$ rails s Success (but elsewhere on the net examples show different output with 'Notice' lines). Library/PostgreSQL/9.2$ sudo su postgresīash-3.2$ createdb -O7stud -Eutf8 test_postgres_developmentīash-3.2$ createdb -O7stud -Eutf8 test_postgres_test So I created the development and test databases: ~$ cd /Library/PostgreSQL/9.2/ Notice that the database.yml file specifies three database names. Then I tried executing the migration again: ~/rails_projects/test_postgres$ bundle exec rake db:migrateįATAL: database "test_postgres_development" does not exist Because I am the user 7stud on my Mac, that means I am executing my rails commands as 7stud, and coupled with the fact that my postgres db was setup with a user named 7stud, that allows me to completely eliminate the username line in config/database.yml: development: 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. I installed prostgres to use with my rails4 app, and I am able to connect to the database server and create databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |