Rails和Devise为注册页面提供错误

时间:2022-11-20 00:27:03

I've googled and SOed for the answer to this, so even though this question is similar to others posed already, please know I have tried all of the answers posted here already.

我已经用谷歌搜索并找到了答案,所以尽管这个问题与其他人提出的问题类似,但请知道我已经尝试了所有已发布的答案。

I've been following a tutorial to set up a Rails site with users etc. I'm at the stage where I tried to use Devise to generate a user db.

我一直在跟随一个教程来设置一个用户等的Rails站点。我正处于尝试使用Devise生成用户数据库的阶段。

I get this error when I try to access the signup page:

我尝试访问注册页面时收到此错误:

ActiveRecord::StatementInvalid in Devise::RegistrationsController#new

The advice I have found is to use rake db:migrate in order to fix the db.

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

This gives me the following error:

这给了我以下错误:

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

The interwebs then leads me to believe that deleting my development.sqlite3 and rerunning rake db:migrate will solve my problem, however this leads to:

然后,interwebs让我相信删除我的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'

again.

[Possibly Related] I also receive the following message when I do just about anything with rails:

[可能相关]当我使用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.

But all of the suggested advice online has yet to fix the issue.

但是,所有在线提出的建议尚未解决问题。

Sorry for the long post, trying to be very thorough, any advice would be appreciated.

对不起,长篇文章,试图非常彻底,任何建议将不胜感激。

Update:

So I can't get it to generate a new schema (I trashed the DB folder several times to try different things) but here is one of the deleted ones:

所以我不能让它生成一个新的模式(我多次破坏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

2 个解决方案

#1


4  

It looks like you have two migrations that both adds an email field to installs. You have to look through all you migration files and see if this is true. There are three ways to add a email field to a table, so look for more then one of these:

看起来您有两个迁移,它们都会添加一个电子邮件字段进行安装。您必须浏览所有迁移文件,看看是否属实。有三种方法可以将电子邮件字段添加到表中,因此请查找以下其中一种方法:

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

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

#3
add_column :installs, :email, :string

#2


4  

Some versions of Devise create migrations without the .rb extension. When I had the same error as you I navigated back to the 'migrate' folder and sure enough the generated migration lacked the extension. Adding .rb and then running $ rake db:migrate fixed this issue for me.

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

#1


4  

It looks like you have two migrations that both adds an email field to installs. You have to look through all you migration files and see if this is true. There are three ways to add a email field to a table, so look for more then one of these:

看起来您有两个迁移,它们都会添加一个电子邮件字段进行安装。您必须浏览所有迁移文件,看看是否属实。有三种方法可以将电子邮件字段添加到表中,因此请查找以下其中一种方法:

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

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

#3
add_column :installs, :email, :string

#2


4  

Some versions of Devise create migrations without the .rb extension. When I had the same error as you I navigated back to the 'migrate' folder and sure enough the generated migration lacked the extension. Adding .rb and then running $ rake db:migrate fixed this issue for me.

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