0

我已经用谷歌搜索并搜索了这个问题的答案,所以即使这个问题与已经提出的其他问题相似,请知道我已经尝试了这里发布的所有答案。

我一直在关注一个教程来建立一个包含用户等的 Rails 站点。我正处于尝试使用 Devise 生成用户数据库的阶段。

当我尝试访问注册页面时出现此错误:

ActiveRecord::StatementInvalid in Devise::RegistrationsController#new

我发现的建议是rake db:migrate用来修复数据库。

这给了我以下错误:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "installs" ADD "email" varchar(255) DEFAULT '' NOT NULL/ruby/testapp/omrails/db/migrate/20130510151217_add_devise_to_installs.rb:5:in `block in up'
/ruby/testapp/omrails/db/migrate/20130510151217_add_devise_to_installs.rb:3:in `up'
/Users/BWS/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `eval'
/Users/BWS/.rvm/gems/ruby-1.9.3-p392/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => db:migrate

然后,互联网使我相信删除我的 development.sqlite3 并重新运行rake db:migrate将解决我的问题,但这会导致:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "installs" ADD "email" varchar(255) DEFAULT '' NOT NULL/ruby/testapp/omrails/db/migrate/20130510151217_add_devise_to_installs.rb:5:in `block in up'

再次。

[可能相关] 当我使用 rails 做任何事情时,我也会收到以下消息:

/Users/BWS/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/yaml.rb:56:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.

但是所有在线建议的建议都还没有解决这个问题。

很抱歉,这篇文章很长,试图非常彻底,任何建议都将不胜感激。

更新:

所以我不能让它生成一个新的模式(我多次删除 DB 文件夹以尝试不同的东西)但这是已删除的模式之一:

# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do

end
4

2 回答 2

4

某些版本的 Devise 创建没有 .rb 扩展名的迁移。当我遇到与您相同的错误时,我导航回“迁移”文件夹,果然生成的迁移缺少扩展名。添加 .rb 然后运行 ​​$ rake db:migrate 为我解决了这个问题。

于 2014-05-29T00:41:01.607 回答
4

看起来您有两个迁移都将电子邮件字段添加到installs. 您必须查看所有迁移文件,看看是否属实。有三种方法可以将电子邮件字段添加到表格中,因此请寻找其中一种以上的方法:

#1
create_table "installs" do |t|
  t.string :email

#2
change_table "installs" do |t|
  t.string :email

#3
add_column :installs, :email, :string
于 2013-05-10T17:57:21.203 回答