【问题标题】:how do I migrate Datamapper on appengine如何在 appengine 上迁移 Datamapper
【发布时间】:2011-02-19 18:00:12
【问题描述】:

我已经从

更改了我的模型
class Place
  include DataMapper::Resource
  has n, :trails

  property :id,           Serial
  property :name,         String,         :length => 140
  property :tag,          String,         :required => true
  timestamps :at 
end

class Place
  include DataMapper::Resource
  has n, :trails

  property :id,           Serial
  property :name,         String,         :length => 140
  property :tag,          String,         :required => true
  property :trail_count,  Integer,        :default => 0
  timestamps :at 
end

我刚刚添加了“属性 :trail_count, Integer, :default => 0”

并且我想迁移现有的 appengine 表以具有额外的字段“trail_count” 我读过 DataMapper.auto_upgrade!应该这样做。

但我得到一个错误“未定义的方法`auto_upgrade!'对于 DataMapper:Module"

您能帮我如何迁移 DM 模型吗?

【问题讨论】:

    标签: ruby-on-rails google-app-engine datamapper migrate


    【解决方案1】:

    第三次重启服务器后,奇迹般地添加了该字段。

    这仍然是一种奇怪且不太好的迁移方式。 如何在没有迁移的情况下操作数据?就像将字段“全名”拆分为名字和姓氏字段?您必须为此进行迁移..

    【讨论】:

      【解决方案2】:

      我一直在查找相同的问题 Roy,并且似乎迁移不适用于使用 datamapper(或任何其他界面)的应用引擎。它是数据存储的一个功能,要更新现有的数据库条目,您必须查询数据库并一次更新一些以避免达到速率限制。 source

      【讨论】:

        【解决方案3】:

        尝试要求 dm-migrations gem。这就是我解决 Sinatra 1.4.7 和 do_sqlite3 0.10.17 问题的方法。

        require 'dm-migrations'

        require 'rubygems'
        require 'sinatra'
        require 'dm-core'
        require 'dm-timestamps'
        require 'dm-sqlite-adapter'
        require 'dm-migrations'
        
        DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/adserver.db")
        
        class Ad
        
          include DataMapper::Resource
        
          property :id,                     Serial
          property :title,                  String
          property :content,                Text
          property :width,                  Integer
          property :height,                 Integer
          property :filename,               String
          property :url,                    String
          property :is_active,              Boolean
          property :created_at,             DateTime
          property :updated_at,             DateTime
          property :size,                   Integer
          property :content_type,           String
        
        end
        
        # Create or upgrade all table at once, like magic
        DataMapper.auto_upgrade!
        

        answer found here

        【讨论】:

          猜你喜欢
          • 2013-10-13
          • 2011-01-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-01
          • 2020-12-28
          • 1970-01-01
          相关资源
          最近更新 更多