Rails - 没有这样的表[rake db:migrate]

时间:2014-02-12 01:25:04

标签: mysql ruby-on-rails ruby database ruby-on-rails-3

我的rails数据库出现问题。我最近恢复了之前的提交,我正试图通过服务器和数据库启动并运行。

我已经运行rake db:migrate和'rake db:create',它们都返回类似的结果

知道怎么解决吗?

rake aborted!
An error has occurred, this and all later migrations canceled:
SQLite3::SQLException: no such table: main.users: CREATE UNIQUE INDEX "index_users_on_email" ON "users" ("email")/Users/Marcus/.rvm/gems/ruby-1.9.3-p448@rails3tutorial2ndEd/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'

包括跟踪

$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
==  AddIndexToUsersEmail: migrating ===========================================
-- add_index(:users, :email, {:unique=>true})
rake aborted!
An error has occurred, this and all later migrations canceled:

如果我能/应该提供更多信息,请告诉我?

感谢

更多信息

$rake db:reset

-- create_table("attendees", {:force=>true})
   -> 0.0120s
-- create_table("competitions", {:force=>true})
   -> 0.0020s
-- create_table("devices", {:force=>true})
   -> 0.0019s
-- create_table("users", {:force=>true})
   -> 0.0045s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
   -> 0.0011s
-- add_index("users", ["remember_token"], {:name=>"index_users_on_remember_token"})
   -> 0.0010s
-- initialize_schema_migrations_table()
   -> 0.0019s
-- assume_migrated_upto_version(20140210000927,     ["/Users/Marcus/Sites/Rails/rails_projects/BattleOfTheBands/db/migrate"])
   -> 0.0066s
You have 1 pending migrations:
  20140211231110 AddDeviseToUsers
Run `rake db:migrate` to update your database then try again.

现在我运行'rake db:migrate'

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/Users/Marcus/.rvm/gems/ruby-1.9.3-p448@rails3tutorial2ndEd/gems/sqlite3-1.3.8/lib/sqlite3/database.rb:91:in `initialize'

3 个答案:

答案 0 :(得分:2)

在我的情况下,我能够通过删除我的盒子上的sqlite3文件来解决这个问题,然后运行:

    rake db:create

然后做:

    rake db:migrate

希望这可以帮助其他人解决同样的问题。

答案 1 :(得分:1)

当你运行db:reset时会创建一个users表,我假设你已经为它添加了一个电子邮件字段,否则索引创建会引发错误。然后运行缺少的迁移以添加设计。 Devise包含一个AddDeviseToUsers类,其中包括:

    change_table(:users) to |t|
       ## Database authenticatable
       t.string :email,              :null => false, :default => ""

这就是它失败的原因。只需从您的用户迁移中删除电子邮件字段,它就可以使用或从设计迁移中删除它。

答案 2 :(得分:0)

rake db:reset对我有用。谢谢!