2012-07-08 74 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