【问题标题】:Why is schema.rb not generated (properly) when running rake db:migrate?为什么在运行 rake db:migrate 时没有(正确)生成 schema.rb?
【发布时间】:2011-01-24 02:20:00
【问题描述】:

我刚刚开始学习 Rails 3 教程,以便对框架有所了解,但我在生成 schema.rb 时遇到了问题。我的操作系统是 Windows 7 x64、Ruby 1.9.2、MySQL2 gem 0.2.6、Rails 3.0.3。

我创建了两个迁移,一个用于我的列表:

class CreateLists < ActiveRecord::Migration
def self.up
  create_table :lists do |t|
    t.string :name
    t.text :description

    t.timestamps
  end
end

def self.down
    drop_table :lists
  end
end

还有一个用于我的列表项:

class CreateItems < ActiveRecord::Migration
  def self.up
    create_table :items do |t|
      t.string :name
      t.string :type
      t.boolean :completed
      t.references :list

      t.timestamps
    end
  end

  def self.down
    drop_table :items
  end

end

Rake 迁移成功,应用程序按预期工作,但 schema.rb 仅显示:

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

# Could not dump table "items" because of following ArgumentError
#   invalid date  

# Could not dump table "lists" because of following ArgumentError
#   invalid date

有没有人对 Rails 更有经验,可以就可能导致问题的原因提供建议?谷歌搜索一无所获。

【问题讨论】:

  • 这可能不会有太大帮助,但我尝试使用 Win7 x32、Ruby 1.9.2、Rails 3.0.3 和 sqlite3 进行迁移,并且效果很好,所以我愿意花钱MySQL2 的问题。
  • 看来您是完全正确的,因为它已通过 SQLite3 适配器正确转储。将在我的 Ubuntu 机器上再试一次,看看这是 Windows 特定的问题还是我的 MySQL 安装有问题。

标签: ruby-on-rails ruby


【解决方案1】:

获取mysql 5.1 libmysql.dll,如下所述:

https://github.com/brianmario/mysql2/issues#issue/71

【讨论】:

    【解决方案2】:

    试试rake db:schema:dump

    【讨论】:

    • 产生与问题中所示相同的输出,即:在删除 schema.rb 并删除 db 后执行 rake db:migrate。
    • 唷,谢谢。由于某种原因 db:structure:dump 总是使用 sql 模式
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 2012-11-18
    • 2014-01-31
    • 2012-02-05
    • 2013-06-13
    • 2011-07-14
    相关资源
    最近更新 更多