Question

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

Posted May 24, 2014 7.4k views
Hi, I followed this tutorial to deploy my first Rails app on Ubuntu / Nginx / Unicorn: https://www.digitalocean.com/community/articles/how-to-launch-your-ruby-on-rails-app-with-the-digitalocean-one-click-image 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.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
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
Submit an Answer