简体   繁体   中英

Ruby on Rails : Development vs Production database - where to enter data?

I'm very new to Rails.

I am confused about the development and production databases. I am using postgreSQL for all of my environments and heroku to host the site. I am able to push migrations and seeds to my production database on heroku. However I entered quite a bit of new data through the browser on localhost:3000. I spent a long time trying to figure out how to get that data to heroku but finally was successful by destroying then creating a new empty database and pushing my development database to it. Now my site on heroku is the same as localhost:3000 using rails server. I modified the database.yaml file so that the development and production databases are now the same name (the name of the development database). But I don't think that means that if I make changes to the development database through localhost:3000 they will automatically be changed on the heroku site. I am very confused about the colors (CRIMSON, MAROON) on heroku - are those different databases than what I specify in the yaml? And I don't know whether I should now be entering new data on the localhost:3000 site or the heroku site. Sorry if this is very amateur. Thank you.

You're getting confused with how Rails uses Databases

Let me explain:


Rails uses the MVC (Model View Controller) programming pattern to populate your applications with database data. Rails uses this pattern because it's the most efficient & extensible, and it works by taking a command from a user (clicks a link, inputs data), sends to the controller & performs the request on the model

The way all rails applications work is to take commands (which you define), and perform database operations with them & then repopulates the app with the new data

Rails is designed to work with a single database, and the database.yml file is there to specify which database that is (it's good practice to have different databases for development, staging & production -- for performance, efficiency & other issues)

This means that the database name is not important - what is important is to keep both databases up to date using the rake db:migrate system to give all databases the required columns to make your app work properly


In answer to your question, the data you have is going to be different for development & production. Your production environment is meant to be that "holy-of-holies" where everything is compiled & running efficiently

The production environment is meant to handle its own data, and should be populated through your application. The reason for development & production databases is to ensure you can "get things wrong" in the development environment before you try and apply it to the production db

If you tell us some more about your specific issues, we'll be able to give a much more refined answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM