I posted my Ruby on Rails project on shared hosting Locum.ru. In the project I use SQLite3. After placing the project, all data from the database is not displayed at all. Placed, given the following instructions: http://locum.ru/blog/hosting/locum-ror-redmine

Did you come up with this command: $ rvm use 1.9.3 do bundle install - path = ~ / projects / redmine / shared / gems - without development test?

In the database.yml file, a connection to SQLite is configured, this file is not touched.

Has anyone come across this?

  • What data you do not have displayed? After the deployment, a new database should be created, on which you should roll your migrations. - AlexDenisov
  • I do online store, on the main should be a list of products. While there are 2 positions with the "fish". They are displayed on the local host, i.e. loaded from the base, but not on the server. I did the migration with the command $ RAILS_ENV = production rvm use 1.9.3 do bundle exec rake db: migrate - Bandicoot87
  • Did you add / create these products at Lokume? - AlexDenisov
  • So is the base not empty? Running the migration simply creates the tables of the desired structure but does not fill them. So after migration, your database is empty. - KryDos
  • @KryDos, and how to fill them in this case? I understand that the migration was successful, but what to do with the data? - Bandicoot87

3 answers 3

The problem is that you do not fill out your database when you migrate to another server.

There are several options to solve this problem.

The first . Add to the end of the file with user model migrations (db / migrate / _timestamp_create_users.rb or something like that) something like this:

User.create(:name => "vasya", :pass => "pupkin") 

Thus, after creating the database, writing to the database will immediately take place.

But this is a very bad option, do not do it.

The second option . Create your own rake task (task) that will do everything you need.

Custom rake tasks should be put here: lib/tasks/

An example of a task that will help you

 namespace :app do desc "Setup production database" task :setup => :environment do # Create Users User.create!(:email => 'admin@example.com', :password => 'passw0rt') end end 

In order to run this task you need to perform actions you already know.

 bundle exec rake app:setup 

These steps need to be done after you have already migrated.

The third option . To migrate existing data to another server, use gem'om yaml_db . This solution works independently of the database, you can migrate, for example, from sqlite3 to mysql or postgres without any special problems.

PS To begin with, I would advise the author to sort out a little with the gaps in knowledge.

PPS Other answers received minuses due to the fact that this is not a solution to the problem, but a crutch, oh bad by the way.

  • Bash on bash - your answer does not solve the problems of an existing project with a heap of entries in the sqlite3 table. Heme rails_db_dump solves this problem in most cases if you need a dump. - Vetal4eg
  • one
    Updated the answer, thanks for the remark. - AlexDenisov

And so, since the essence of the error was understood from the comments. I will try to explain to you why nothing is displayed.

On localhost, you used SQLite3, filled it in, created migrations. After you moved your site to a new hosting you started the migration and it was successful. But migration is just a set of SQL commands that describe the structure of your database. Ie what columns and tables in it should be. No more. That is, after starting the migration, no data is transferred. All that you have completed on the local machine will not be transferred to the hosting only through migration.

Since you are using SQLite3 (and this is just a file), you can simply copy it from the local host to your hosting. This should help.

Or maybe you can somehow export data to SQLite and then import it on your hosting ... I'm sorry, not selenium in this :(

  • I thank, the problem was solved. I'm used to working with MySQL, the logic of SQLite is not entirely clear) - Bandicoot87
  • Logics? This is the base in the text file (: - Vetal4eg

Copy your development.sqlite3 to a server named production.sqlite3

  • Thank you for your answer, but for some reason he got a minus) For now I’ll consider other options - Bandicoot87
  • It is quite a correct option, I think. Try it. Do not pay attention to the minus. - KryDos
  • Do you need a quick fix? You got it; D - Vetal4eg
  • @KryDos, stop giving bad advice. And what about the other DB? What will you copy then? - AlexDenisov
  • 1101_debian, I don’t see anything harmful in the context of the question - Vetal4eg