Not possible to create MySQL database from schema.rb for Rails 4 app?

May 24, 2014 5.5k views
Hi, I followed this tutorial to deploy my first Rails app on Ubuntu / Nginx / Unicorn: However, in my Rails production log I see this: E, [2014-05-24T11:48:34.711858 #13238] ERROR -- : Mysql2::Error: Table 'rails.users' doesn't exist: SELECT `users`.* FROM `users` WHERE `users`.`remember_token` IS NULL LIMIT 1 I, [2014-05-24T11:48:34.712349 #13238] INFO -- : Completed 500 Internal Server Error in 48ms When I take a closer look at my "rails" database I can see that it contains only one table ("schema_migrations") where there should be more than a dozen. Running commands like RAILS_ENV=production rake db:migrate or RAILS_ENV=production rake db:create db:schema:load seems to have no effect on the database. But strangely I don't get any error messages when running those commands. How can I create the database for my app from schema.rb? Thanks for any help.
4 Answers
Your rake commands need to be the first on the line. The Rails environment goes at the end. The way you have done it, you have set the Rails environment variable to "production rake db:create db:schema:load". That's why it doesn't complain. You can set the environment variable to anything you want, whether it makes sense or not.
Let me revise that. You can do it the way you have it, but make sure you put a semicolon after the Rails environment.
RAILS_ENV=production; rake db:create db:schema:load
They are two separate commands.
Thanks a lot for your help. But actually that doesn't change much. It still won't create my database.
Have you tried running the commands separately?
RAILS_ENV=production rake db:create

RAILS_ENV=production rake db:schema:load
Have another answer? Share your knowledge.