0

次のステートメントを使用します。

rails generate scaffold Product title:string description:text image_url:string price:decimal

生成された移行を少し編集すると、次の移行があります。

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.string :title
      t.text :description
      t.string :image_url
      t.decimal :price, precision: 8, scale: 2

      t.timestamps
    end
  end
end

その後、次のコマンドを正常に実行しました。

rake db:migrate

データベースに接続して、本当にテーブルが作成されていることを確認します。次に、実行します

rake test

多くのエラーが発生しました。私が信じる問題の原因は、レールが「製品」テーブルを見つけられないことです。

 1) Error:
test_should_create_product(ProductsControllerTest):
ActiveRecord::JDBCError: Table products does not exist
    arjdbc/jdbc/RubyJdbcConnection.java:115:in `columns'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-jdbc-adapter-1.2.7/lib/arjdbc/db2/adapter.rb:514:in `columns'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:660:in `column_names'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:651:in `timestamp_column_names'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:585:in `table_rows'
    org/jruby/RubyHash.java:1257:in `each'
    org/jruby/RubyEnumerable.java:718:in `map'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:579:in `table_rows'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:494:in `create_fixtures'
    org/jruby/RubyArray.java:1613:in `each'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:492:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:491:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:168:in `disable_referential_integrity'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:476:in `create_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:895:in `load_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activerecord-3.2.12/lib/active_record/fixtures.rb:849:in `setup_fixtures'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:432:in `_run__858744690__setup__1004892786__callbacks'
    org/jruby/RubyBasicObject.java:1659:in `__send__'
    org/jruby/RubyKernel.java:2086:in `send'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:390:in `_run_setup_callbacks'
    org/jruby/RubyBasicObject.java:1659:in `__send__'
    org/jruby/RubyKernel.java:2086:in `send'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /home/gotqn/.rvm/gems/jruby-1.7.2/gems/activesupport-3.2.12/lib/active_support/testing/setup_and_teardown.rb:35:in `run'

私の知る限り、テストが行​​われると、私の「テスト」データベースが消去され、「開発」データベースの移行が適用されます。「IBMDB2Express10.1」データベースを使用しているため、テストを担当するファイルにいくつかの変更を加える必要があると思います。

これを解決するのを手伝ってくれませんか。

以下に、状況全体に関する詳細情報を表示しました。

  1. 「IBMDB2Express」バージョン10.1の使用
  2. jRuby1.7.2の使用
  3. Railsバージョン3.2.12の使用
  4. Ubuntu10.04LTCを使用する
  5. これが私の「database.yml」ファイルの外観です。
development:
    adapter: jdbc
    driver: com.ibm.db2.jcc.DB2Driver
    url: jdbc:db2://localhost:50000/ddevelop
    host: localhost
    port: 50000
    database: ddevelop
    username: db2inst1
    password: pass

test:
    adapter: jdbc
    driver: com.ibm.db2.jcc.DB2Driver
    url: jdbc:db2://localhost:50000/dtest
    host: localhost
    port: 50000
    database: dtest
    username: db2inst1
    password: pass

注:「dtest」データベースはすでに作成されています。

4

1 に答える 1

1

テストデータベースはまだ更新されていません。rake db:test:prepareの後に実行する必要がありますrake db:migration。今すぐ実行して、再試行できます。

于 2013-02-23T16:41:35.650 に答える