2010-05-14 36 views
3

我已經改變了我的模型從我怎麼遷移DataMapper的AppEngine上

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,整型:默認=> 0」

並且我想遷移現有的appengine表,讓我有更多的字段「trail_count」 我讀過DataMapper.auto_upgrade!應該這樣做。

但我得到一個錯誤「未定義的方法`auto_upgrade!'對於DataMapper:模塊「

你能請幫助我如何遷移DM模型?

回答

1

第三次重新啓動服務器後,奇怪地添加了該字段。

這仍然是一個奇怪的,不是很好的方式來進行遷移。 如何在沒有遷移的情況下操作數據?比如將字段「全名」分割爲姓和名字段?你必須有一個遷移..

0

我一直在尋找同樣的問題羅伊,似乎遷移不適用於應用程序引擎使用數據映射(或任何其他接口)。這是數據存儲的功能,爲了更新現有的數據庫條目,您必須一次查詢數據庫並更新一些數據庫,以避免達到速率限制。 source

0

嘗試要求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

相關問題