3

I am using sqlite for both (for now) my development and production system on rails. I have a development.sqlite3 file that I want to copy over to production.sqlite3 to run some testing in a production environment.

I've tried to copy the development db over to the production just by doing mv development.sqlite3 production.sqlite3 and that doesn't seem to be working.

Any ideas on how best to go about doing this?

1 Answer 1

4

According to this question the following code does it.

RAILS_ENV=production rake db:create db:schema:load

This empties out the current production.sqlite3. After the database creation and loading of the structure you can copy the development.sqlite3 to production.sqlite3 to copy your data.

cp db/development.sqlite3 db/production.sqlite3
Sign up to request clarification or add additional context in comments.

5 Comments

I've tried that and it doesn't seem to be working. Is there a way to test to make sure the data is in production.sqlite3 and a way to make sure that rails knows it is in the production environment.
I just ran select * from posts; inside of sqlite3 and confirmed there is no data in the db. Am I doing something wrong? I ran those commands from the command line and it seemed to work with output that you would expect.
To start rails server in production you run rails server production, and to start the console you run rails console -e production. You found no data in production.sqlite3 with sqlite3? If you've copied development.sqlite3 you should have the exact same data, no matter what Rails can see.
Did you copy the file again after db:create and db:schema:load? Otherwise it actually should be empty, as db:schema:load clears out the current db.
yeah, I forgot to copy it over after I ran that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.