ruby-on-rails – 由于我的用户表中的重复列–Rails 3.1,Devise rake db:migrate失败

栏目: Ruby · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/7453981/devise-rake-dbmigrate-fails-because-of-duplicate-column-in-my-users-table-ra

这是我第一次安装Devise并运行rake db:migrate时遇到的错误:

==  AddDeviseToUsers: migrating ===============================================
-- change_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL

鉴于这只是测试数据,我可以删除我的数据库中的那个列并重新运行它,但这似乎不是Railsy – 如果只是因为它将使我的登台服务器(唯一的其他服务器与我的应用程序与我的localhost不同步.

此外,如果与另一列发生冲突,该怎么办?

因此,在运行迁移之前,这是我的User表的架构,我该如何处理?迁移某种重命名的迁移?

# == Schema Information
#
# Table name: users
#
#  id         :integer         not null, primary key
#  email      :string(255)
#  f_name     :string(255)
#  l_name     :string(255)
#  username   :string(255)
#  role_id    :integer
#  picture    :string(255)
#  about_me   :string(255)
#  website    :string(255)
#  created_at :datetime
#  updated_at :datetime
#
尝试rake db:rollback然后再试一次.当你第一次添加id列时这样做.为什么要添加id:integer not null,主键是自动在rails中.它应该如下所示:
class CreateProducts < ActiveRecord::Migration
  def up
    create_table :products do |t|
      t.string :email
      t.text :f_name

      t.timestamps
    end
  end

  def down
    drop_table :products
  end
end

您可以在这里获得更多信息 http://guides.rubyonrails.org/migrations.html

翻译自:https://stackoverflow.com/questions/7453981/devise-rake-dbmigrate-fails-because-of-duplicate-column-in-my-users-table-ra


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

PHP and MySQL Web Development (3rd Edition) (Developer's Library

PHP and MySQL Web Development (3rd Edition) (Developer's Library

Luke Welling、Laura Thomson / Sams / 2004-09-29 / USD 49.99

We've taken the best and made it even better. The third edition of the best-selling PHP and MySQL Web Development has been updated to include material and code on MySQL 5, PHP 5 and on PHPs object mod......一起来看看 《PHP and MySQL Web Development (3rd Edition) (Developer's Library》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

在线进制转换器
在线进制转换器

各进制数互转换器

MD5 加密
MD5 加密

MD5 加密工具