rsyudouのRuby日記

 | 

2007-04-15

[]マイグレーションの実行に失敗中

解決しました!DBI標準で入ってるとばっかり orz

以下のパッケージを追加インストール。

||/ 名前                          バージョン                    説明
+++-=============================-=============================-==========================================================================
ii  libdbd-mysql-ruby1.8          0.1.1-4                       Ruby/DBI MySQL driver for Ruby 1.8
ii  libdbi-ruby1.8                0.1.1-4                       Database Independent Interface for Ruby 1.8
ii  libmysql-ruby1.8              2.7.3-1                       MySQL module for Ruby 1.8
  • 実行結果
# db:migrate
(in /home/syudou/rails/hello)
== CreateMessages: migrating ==================================================
-- create_table(:messages)
   -> 0.5195s
== CreateMessages: migrated (0.5197s) =========================================

やっと次に進める:)

*

先週からrailsの勉強を始めたのですが、昨日からマイグレーションの実行ではまっています。

お分かりの方がいましたら助言お願いします。

参考書籍はこちらです。

Ruby on Rails入門優しいRailsの育て方

Ruby on Rails入門優しいRailsの育て方

現在、p136 のマイグレーションの実行で結果が合いません。

環境

debian GNU/Linux sid

ruby 1.8.2-1

rails 1.1.6-3

rake 0.7.1-2

これまでの操作

プロジェクト作成とDB作成

# cd ~
# mkdir rails
# cd rails
# rails hello
# mysqladmin create hello -p
  • database.yml のdevelopment:の部分を修正
# vi config/database.yml

development:
  adapter: mysql
  database: hello
  username: syudou
  password: dbpass
  host: localhost
  • "model"ジェネレータの実行
# ruby script/generate model Message
      create  app/models/
      create  test/unit/
      create  test/fixtures/
      create  app/models/message.rb
      create  test/unit/message_test.rb
      create  test/fixtures/messages.yml
      exists  db/migrate
      create  db/migrate/001_create_messages.rb
  • db/migrate/001_create_messages.rb を修正
# vi db/migrate/001_create_messages.rb

class CreateMessages < ActiveRecord::Migration
  def self.up
    create_table :messages do |t|
       t.column :name, :string
       t.column :value, :string
    end
  end

  def self.down
    drop_table :messages
  end
end
# rake db:migrate
(in /home/syudou/rails/hello)
rake aborted!
wrong number of arguments (1 for 0)

(See full trace by running task with --trace)
# rake db:migrate --trace
(in /home/syudou/rails/hello)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
wrong number of arguments (1 for 0)
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `initialize'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `new'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:551:in `scramble41'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/vendor/mysql.rb:141:in `real_connect'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:330:in `connect'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:87:in `initialize'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `new'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:36:in `mysql_connection'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in `send'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:251:in `connection_without_query_cache='
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/query_cache.rb:54:in `connection='
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:220:in `retrieve_connection'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'
/home/syudou/rails/hello/config/../vendor/rails/activerecord/lib/active_record/migration.rb:282:in `migrate'
/home/syudou/rails/hello/config/../vendor/rails/railties/lib/tasks/databases.rake:4
/usr/lib/ruby/1.8/rake.rb:387:in `call'
/usr/lib/ruby/1.8/rake.rb:387:in `execute'
/usr/lib/ruby/1.8/rake.rb:387:in `each'
/usr/lib/ruby/1.8/rake.rb:387:in `execute'
/usr/lib/ruby/1.8/rake.rb:357:in `invoke'
/usr/lib/ruby/1.8/rake.rb:350:in `synchronize'
/usr/lib/ruby/1.8/rake.rb:350:in `invoke'
/usr/lib/ruby/1.8/rake.rb:1924:in `run'
/usr/lib/ruby/1.8/rake.rb:1924:in `each'
/usr/lib/ruby/1.8/rake.rb:1924:in `run'
/usr/bin/rake:4

  • mysqlへの接続確認
# mysql hello -u syudou -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 95
Server version: 5.0.38-Debian_1-log Debian etch distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SELECT * FROM mysql.user WHERE User='syudou' \G
*************************** 1. row ***************************
                 Host: %
                 User: syudou
             Password: *FA772E0932809535E43FEDEA5BC7473E262670AF
          Select_priv: Y
          Insert_priv: Y
          Update_priv: Y
          Delete_priv: Y
          Create_priv: Y
            Drop_priv: Y
          Reload_priv: Y
        Shutdown_priv: Y
         Process_priv: Y
            File_priv: Y
           Grant_priv: Y
      References_priv: Y
           Index_priv: Y
           Alter_priv: Y
         Show_db_priv: Y
           Super_priv: Y
Create_tmp_table_priv: Y
     Lock_tables_priv: Y
         Execute_priv: Y
      Repl_slave_priv: Y
     Repl_client_priv: Y
     Create_view_priv: Y
       Show_view_priv: Y
  Create_routine_priv: Y
   Alter_routine_priv: Y
     Create_user_priv: Y
             ssl_type:
           ssl_cipher:
          x509_issuer:
         x509_subject:
        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0
*************************** 2. row ***************************
                 Host: localhost
                 User: syudou
             Password: *FA772E0932809535E43FEDEA5BC7473E262670AF
          Select_priv: Y
          Insert_priv: Y
          Update_priv: Y
          Delete_priv: Y
          Create_priv: Y
            Drop_priv: Y
          Reload_priv: Y
        Shutdown_priv: Y
         Process_priv: Y
            File_priv: Y
           Grant_priv: Y
      References_priv: Y
           Index_priv: Y
           Alter_priv: Y
         Show_db_priv: Y
           Super_priv: Y
Create_tmp_table_priv: Y
     Lock_tables_priv: Y
         Execute_priv: Y
      Repl_slave_priv: Y
     Repl_client_priv: Y
     Create_view_priv: Y
       Show_view_priv: Y
  Create_routine_priv: Y
   Alter_routine_priv: Y
     Create_user_priv: Y
             ssl_type:
           ssl_cipher:
          x509_issuer:
         x509_subject:
        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0
2 rows in set (0.00 sec)

あやしい所

rakerailsのバージョンの問題でしょうか。よくわかっていないrakeについて調べています。

 |