简体   繁体   中英

rake db:migrate error tables

I am trying to run rake db:migrate and am receiving an error in the console.

It seems as though I am creating a table that already exists, yet I don't know how to remove the old table, or reset the db to start fresh.

I don't have any users so erasing or starting from fresh won't be an issue.

create_table(:users) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255) DEFAULT '' NOT NULL, "encrypted_password" varchar(255) DEFAULT '' NOT NULL, "reset_password_token" varchar(255), "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar(255), "last_sign_in_ip" varchar(255), "created_at" datetime, "updated_at" datetime) /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'

If you don't mind erasing data you can run

rake db:drop
rake db:create
rake db:migrate

and that should fix it. Otherwise you can for the moment comment out the part of the content causing problems in the change (or up) method in your migration and then run the migrations. After the migration is run uncomment the migration.

Doing this tricks rails into accepting that the migrations are up to date.

You can reset database by using

$ rake db:reset

Or if you want to undo your migration you can use

$ rake db:rollback

Or if you want to update your table, you may change it in your migration file from create_table to change_table

create_table :users do |t|

to

change_table(:users) do |t|

看起来你没有任何用户迁移,但你有迁移来更改用户表。你试图改变用户表而不存在它。如果你有模式文件,那么你可以使用rake db:schema从那里加载你的数据库:dump命令。

You already have the users table created. Looks like the migration was already run and there is no need to run it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM