迁移失败,错误:NoMethodError:未定义的方法`Migration'

时间:2012-07-08 21:48:57

标签: ruby migration sequel nomethoderror

我正试图在Ruby中设置Sequel。我去了http://sequel.rubyforge.org/rdoc/files/doc/migration_rdoc.html并创建了我的第一次迁移。然后我将Postgres.app作为我的服务器运行并创建了一个createdb Qsario。当我尝试使用迁移创建数据库字段时出现问题:

$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

请注意,没有Rakefile或类似的东西,因为我仍然试图设置东西。我没有使用Rails。所以.rb文件是目录中唯一的东西。

1 个答案:

答案 0 :(得分:1)

仅仅是为了记录,这是固定迁移的样子,并附有修复/改进的评论,以防其他人犯同样的错误。 mu太短,值得我帮忙修理它。

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