2014-02-05 42 views
0

這是我在終端中得到的錯誤。哪裏不對?

DeviseCreateUsers: migrating 
-- create_table(:users) rake aborted! 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/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `new' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `prepare' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:134:in `execute' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `block in execute' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:435:in `block in log' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in > `instrument' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract_adapter.rb:430:in `log' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:331:in `execute' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/schema_statements.rb:190:in `create_table' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:625:in `block in method_missing' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `block in say_with_time' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:597:in `say_with_time' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:617:in `method_missing' 
/Users/danieljuzovitskij/Desktop/pinteresting/db/migrate/20140205151417_devise_create_users.rb:3:in `change' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:571:in `exec_migration' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:555:in `block (2 levels) in migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:554:in `block in migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:553:in `migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:709:in `migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:959:in `block in execute_migration_in_transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `block in ddl_transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/transactions.rb:209:in `transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:1005:in `ddl_transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:958:in `execute_migration_in_transaction' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:920:in `block in migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `each' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:916:in `migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:764:in `up' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/migration.rb:742:in `migrate' 
/Users/danieljuzovitskij/.rvm/gems/ruby-2.0.0-p353/gems/activerecord-4.0.2/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>' 
Tasks: TOP => db:migrate (See > full trace by running task with --trace) 
------------------------------------------------------------------------ 
+1

看起來像表已經創建。檢查文件'db/scheme.rb'並查看用戶表是否存在 –

+1

看起來你已經擁有'users'表。放下它,然後再試一次。 –

回答

0

看起來您的遷移與您的數據庫不同步。如果這是一個開發環境,我建議你做下面的rake任務。

rake db:drop 
rake db:create 
rake db:migrate 
+0

謝謝!有效。 – Danju

0

的SQLite3 ::的SQLException:表 「用戶」 已經存在:

該錯誤意味着你的 「用戶」 表已創建。要麼刪除表,要麼確保稍後的遷移不會嘗試重新創建它。

0

失敗的遷移稱爲DeviseCreateUsers。我建議檢查this.這是如何添加Devise到已經創建的用戶模型。

我建議回滾你最後的變化(如創建失敗的遷移),並做到這一點。只是爲了一致性:

rails g devise user 

將增加遷移所需,並檢查是否已經創建或不表。

0

使用 力:真正

create_table :users, force: true do |t| 
// your contents 
end 

它會刪除現有表並創建新的。

+0

@ user2167127是否適合您? – sunil