$ bundle exec rake db:migrate
While working on Chapter 6 of the Michael Hartl Ruby on Rails tutorial, I kept getting a crazy long error. This is an example of that error:
== 20141129134103 CreateUsers: migrating ======================================
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` (`id` int(11) auto_increment PRIMARY KEY, `name` varchar(255), `created_at` datetime, `updated_at` datetime) ENGINE=InnoDB/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `query'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:303:in `block in execute'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-4.1.8/lib/active_record/migration.rb:621:in `block in say_with_time'
/home/barry/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
Tasks: TOP => db:migrate
The error was occurring because I had already created a table named Users. To solve this, I wanted to reset my database back to the original. I used
$ rake db:reset
and then ran
$ bundle exec rake db:migrate
and everything worked perfectly!
rake db:migrate:down # To have rails remove the table and keep in sync*
delete ('drop table users') the table in mysql and then re-run the migrations.
Use rake db:reset as indicated by jykim to drop the database.
Today is day 2 of the Coder Manual lessons. I ended up paying the $39 price from Stacksocial for the online CoderManual course by Rob Dey, which was originally $399. At $39 and with lifetime access to the material, I didn’t think it was a bad investment.
I completed Phase 1 and Part 1 yesterday. Today I will be doing the Part 2 videos. So far the videos are pretty easy to follow and not too long so as to lose focus. Rob explains things in an easy to understand manner and it’s been great following along. As great as that sounds, Phase 1 was just an intro to computers and the internet, and Part 1 was just making sure you had the necessary software installed, so it wasn’t much in-depth coding. We’ll see how Part 2 is today.
Will keep you posted!
WOW, I’ve spent way too many hours trying to figure out why I was getting this error message when trying to push my changes to the ‘filling-in-layout’ branch of sample_app project.
sunsplat@rails-tutorial:~/workspace/sample_app (filling-in-layout) $ git push origin filling-in-layout
fatal: 'modeling-users' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
After reading countless posts on this subject from various resources, this link was the most helpful: http://stackoverflow.com/questions/17307154/git-bash-push-to-bitbucket-ignores-ssh-key
I went into the ‘.git’ folder in my sample_app project to see what was going on. For some reason, in the /.git/config file, my remote ‘origin’ URL was set to ‘modeling-users’ when it should have been set to the Bitbucket URL for the project. I’ve changed it accordingly and it has solved the problem.
url = firstname.lastname@example.org:sunsplat/sample_app.git
fetch = +refs/heads/*:refs/remotes/origin/*
remote = origin
merge = refs/heads/master
This is a good git command to remember:
git remote add origin URL_TO_YOUR_REPO