我正在尝试运行 rake db:migrate ,并在控制台中收到错误。
似乎我正在创建一个已经存在的表,但我不知道如何删除旧表,或者重置db以开始新鲜。 / p>
我没有任何用户如此擦除或从新鲜开始不会是一个问题。
create_table(:users)rake aborted! StandardError:一个错误发生,这个和所有后来的迁移被取消:
SQLite3 :: SQLException:表users已经存在:CREATE TABLE users(idINTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,email varchar(255)DEFAULT''NOT NULL,encrypted_passwordvarchar(255) DEFAULT''NOT NULL, reset_password_tokenvarchar(255),reset_password_sent_atdatetime,remember_created_atdatetime,sign_in_countinteger DEFAULT 0 NOT NULL,current_sign_in_at datetime,last_sign_in_atdatetime,current_sign_in_ip varchar(255),last_sign_in_ipvarchar(255),created_atdatetime,updated_atdatetime) /Users/jovanhernandez/.rvm/gems/ruby-2.1。 2 / gems / sqlite3-1.3.9 / lib / sqlite3 / database.rb:91:in `initialize'
解决方案
如果您不介意删除数据,您可以运行
rake db:drop rake d b:创建 rake db:migrate,应该修复它。否则,您可以暂时注释掉部分内容,导致迁移中的更改(或向上)方法出现问题,然后运行迁移。迁移后,迁移将被移除。
执行此操作可以接受迁移是最新的。
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:migrateand 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.
更多推荐
rake db:migrate错误表
发布评论