ruby-on-rails - Ruby on Rails n00b。 rake 分贝 :migrate fail

标签 ruby-on-rails sqlite rake dbmigrate

ROR 的新手。我正在服用一个月的铁路并且:

我无法通过 f'n $ rake db:migrate!!!!

我现在收到这条消息

gregs-MacBook-Air:trydah gregfrontiero
$ rake db:migrate

== 20140606025644 AddDeviseToUsers: migrating =================================

-- change_table(:users)

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: no such table: users: ALTER TABLE "users" ADD "email" varchar(255) DEFAULT '' NOT NULL/Users/gregfrontiero/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:ininitialize' "`



我在 StackOverflow 上看到一些东西说要重置并得到这个:
gregs-MacBook-Air:trydah gregfrontiero$ rake db:reset

/Users/gregfrontiero/Desktop/trydah/db/schema.rb doesn't exist yet. Runrake db:migrateto create it, then try again. If you do not intend to use a database, you should instead alter /Users/gregfrontiero/Desktop/trydah/config/application.rb to limit the frameworks that will be loaded.



如果你让我知道如何解决这个问题,我会为你 build 几座神殿。

再次感谢,

格雷格

最佳答案

如评论中所述,错误清楚地说明了这一点:

no such table: users

您遇到的问题是您试图更改一个不存在的表。如果您在之前的迁移中创建了该表并在您的服务器上删除了该表,您可能需要使用 rake db:reset ,但是由于您已经使用该命令出错,因此您可能必须设置一个新表。

--

我认为你最好这样做:
$ rails g migration CreateUserTable

#db/[timestamp]_create_users.rb
class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
        #... columns here
        t.timestamps
    end
  end
end

如果您随后从当前的迁移中删除内容 - 允许您运行这个新的,您将能够通过运行 rake db:migrate 创建数据库.之后,您需要创建一个新的迁移,复制注释掉的迁移,然后粘贴到新迁移中。

这将允许您运行 change数据库中的命令,因为 db 将存在于系统中。

关于ruby-on-rails - Ruby on Rails n00b。 rake 分贝 :migrate fail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24073867/

相关文章:

mysql - Rails 查询/范围 : exclude objects according to attribute of joined model

java - 在 Android 的 SQLite 中创建表有问题

ios - 图像未从 objective-c 中的 sql 数据库中检索

ruby-on-rails - rake db :structure:dump 上的 nil nilclass 的未定义方法 'exitstatus'

ruby-on-rails - 有没有办法让 "rake routes"看起来更好?

ruby-on-rails - 如何在 Rails 中使用雷神?

ruby-on-rails - 如何向卖家提供订单详细信息 Stripe

ruby-on-rails - 乘客 bundler /设置 LoadError

sqlite - 如何在 Debian 上安装 sqlite

ruby-on-rails - rake-pipeline 在指定的输出目录中进行脂肪转储,我该如何停止呢?