Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new to rails, setting up db then running rake db:create/migrate

hi im currently learning rails, and following a tutorial. the instructions were to edit the migration file after i've created the app, then running rake db:migrate, then rake db:create.

i've edited the migration file to this:

class CreateUsers < ActiveRecord::Migration   def change     create_table :users do |t|       t.string :username       t.string :email       t.string :encrypted_password       t.string :salt       t.timestamps     end   end end 

then when i've run 'rake db:migrate' i got an error

Mysql2::Error: Table 'users' already exists: CREATE TABLE `users` ... 

after i'm supposed to run 'rake db:create', then im getting this

user_auth_development already exists user_auth_test already exists 
like image 420
Harvey Katrina Avatar asked May 26 '13 10:05

Harvey Katrina


Video Answer


1 Answers

You run rake db:create once and only once, and you run it first. Then you run rake db:migrate every time you add/change a migration. You've either already run this migration, or you are pointing at a database that already exists and already contains a table named users. My guess is that you ran the migration once already, in which case you're probably good to go. If you want to nuke the DB and start over, do rake db:drop db:create db:migrate.

like image 186
Jim Stewart Avatar answered Oct 13 '22 22:10

Jim Stewart