mysql - Can not migrate a new model using Rails 3 -


i trying create new table using rails 3. first created model rails g model vendor name:string address:string. when typed rake db:migrate` gave me following error.

error: mysql::error: table 'users' exists

c:\site\swargadwara_puri>rake db:migrate ==  createusers: migrating ==================================================== -- create_table(:users) rake aborted! standarderror: error has occurred, later migrations canceled:  mysql::error: table 'users' exists: create table `users` (`id` int(11) d efault null auto_increment primary key, `contact_name` varchar(255), `login_id` varchar(255), `password_hash` varchar(255), `password_salt` varchar(255), `phone ` varchar(255), `address` varchar(255), `created_at` datetime not null, `updated _at` datetime not null) engine=innodbc:/site/swargadwara_puri/db/migrate/2015041 9131135_create_users.rb:3:in `change' c:in `migrate' 

20150419131135_create_users.rb

class createusers < activerecord::migration   def change     create_table :users |t|       t.string :contact_name       t.string :login_id       t.string :password_hash       t.string :password_salt       t.string :phone       t.string :address        t.timestamps     end   end end 

i have table named user in same database before. tried command rake db:migrate version=201504...... still getting same error. please me resolve error , create new table successfully.

problem in case have created user table , 20150419131135_create_users.rb migration file try create again user table. suggest take backup of file in local system. temporary remove file db/migration directory. , run

rake db:migrate 

it solve problem.

now, said in chat have not other migration file create_user , think may lost migration file created before while creating user table or may created user table in different way(not rake db:migrate don't have other file in ur migration directory).

so, follow this:

  1. export user table's data mysql , save file on system.
  2. drop user table mysql
  3. again put temporarily removed 20150419131135_create_users.rb file in db/migrate directory
  4. run rake db:migrate create user table
  5. import user data in user table exported in step 1

in way issue of migration resolved forever , not lost existing data of user table.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -