2012-07-08 129 views
0

我想在Ruby中設置Sequel。我去了http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html並創建了我的第一次遷移。然後我將Postgres.app作爲我的服務器運行,並創建了一個已創建的Qsario。問題是當我嘗試使用我的移民來創建數據庫字段:遷移失敗,錯誤:NoMethodError:未定義的方法`遷移'

$sequel -E -m . postgres://localhost/Qsario 
I, [2012-07-08T13:53:49.659795 #6258] INFO -- : (0.000374s) SET standard_conforming_strings = ON 
I, [2012-07-08T13:53:49.660113 #6258] INFO -- : (0.000153s) SET client_min_messages = 'WARNING' 
I, [2012-07-08T13:53:49.660359 #6258] INFO -- : (0.000163s) SET DateStyle = 'ISO' 
I, [2012-07-08T13:53:49.664679 #6258] INFO -- : (0.000952s) SELECT NULL FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.665179 #6258] INFO -- : (0.000214s) SELECT * FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.665544 #6258] INFO -- : (0.000166s) SELECT 1 AS "one" FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.666100 #6258] INFO -- : (0.000325s) SELECT COUNT(*) AS "count" FROM "schema_info" LIMIT 1 
I, [2012-07-08T13:53:49.666461 #6258] INFO -- : (0.000179s) SELECT "version" FROM "schema_info" LIMIT 1 
Error: NoMethodError: undefined method `Migration' for Sequel:Module/Users/me/Projects/Qsario/db/migrate/001_create_user_and_file_tables.rb:3:in `<top (required)>' 

這裏的001_create_user_and_file_tables.rb的樣子:

Sequel.Migration do 
    no_transaction 

    change do 
    create_table(:users) do 
     primary_key :id 
     String  :username, :unique=>true 
     String  :email, :unique=>true 
     String  :password_hash 
     String  :password_salt 
     DateTime :joined_at, :null => false 
     FalseClass :banned, default=>false 
     String  :role, default=>"user" 
    end 

    create_table(:files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     String  :filename, :null => false 
     DateTime :uploaded_at, :null => false 
    end 

    create_table(:users_files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     foreign_key :file_id, :files 
    end 
    end 
end 

注意,沒有Rake文件之類的東西,因爲尚未我仍然試圖讓事情成立。我沒有使用Rails。這樣.rb文件是目錄中唯一的東西。

+1

你想['Sequal.migration',不'Sequel.Migration'(http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html)。 – 2012-07-08 21:54:44

+0

Sequal?這不會有多大的幫助:)但是,Sequel.migration DID可以工作,一旦我將default更改爲:default。謝謝! – Qsario 2012-07-08 22:36:47

+0

一個拼寫mistaek值得另一個:) – 2012-07-08 22:47:18

回答

1

只是爲了記錄,以下是固定遷移的樣子,以及有關修復/改進的意見,以防其他人犯同樣的錯誤。畝太短,值得所有信貸幫助我解決它。

Sequel.migration do # Lowercase 'm' in migration 
    # That no_transaction bit was totally unnecessary. 

    change do 
    create_table(:users) do 
     primary_key :id 
     String  :username, :unique=>true 
     String  :email,  :unique=>true 
     String  :password_hash 
     String  :password_salt 
     DateTime :joined_at, :null => false 
     FalseClass :banned,  :default=>false # default needs to be :default 
     String  :role,  :default=>"user" 
    end 

    create_table(:files) do 
     primary_key :id 
     foreign_key :user_id, :users 
     String  :filename, :null => false 
     DateTime :uploaded_at, :null => false 
    end 

    # A nicer way to make the old :users_files table. 
    create_join_table(:user_id => :users, :file_id => :files) 
    end 
end